Last active
February 14, 2018 17:35
-
-
Save t3knoid/3e7350b2fe94b4fc2ab2c6877e6ecbb9 to your computer and use it in GitHub Desktop.
Jenkins Groovy Web Login RESTful Authentication method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* Use this method to get an authentication token for a given URL and authentication string | |
* @param auth is an authentication string in the form of username:password or username:authtoken | |
* @param addr is the url to access | |
***/ | |
def requestConnection(auth,addr) | |
{ | |
def authString = "${auth}".getBytes().encodeBase64().toString() // Use authentication token | |
def conn = addr.toURL().openConnection() | |
if (authString.length() > 0) | |
{ | |
conn.setRequestProperty( "Authorization", "Basic ${authString}" ) | |
} | |
return conn | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment