Skip to content

Instantly share code, notes, and snippets.

@t3knoid
Last active February 14, 2018 17:35
Show Gist options
  • Save t3knoid/3e7350b2fe94b4fc2ab2c6877e6ecbb9 to your computer and use it in GitHub Desktop.
Save t3knoid/3e7350b2fe94b4fc2ab2c6877e6ecbb9 to your computer and use it in GitHub Desktop.
Jenkins Groovy Web Login RESTful Authentication method
/***
* 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