Skip to content

Instantly share code, notes, and snippets.

@naturalett
Created February 23, 2020 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naturalett/af02748785c8aa6051dbb70e0dfa1ca2 to your computer and use it in GitHub Desktop.
Save naturalett/af02748785c8aa6051dbb70e0dfa1ca2 to your computer and use it in GitHub Desktop.
getToken
INSTALLATION_ID = <INSTALLATION_ID>
def getToken(jsonWebToken) {
try {
def httpConn = new URL("https://api.github.com/app/installations/${INSTALLATION_ID}/access_tokens").openConnection();
httpConn.setRequestProperty( 'Authorization', "Bearer ${jsonWebToken}" )
httpConn.setRequestProperty( 'Accept', 'application/vnd.github.machine-man-preview+json' )
httpConn.setRequestMethod("POST");
def responseText = httpConn.getInputStream().getText()
def slurper = new JsonSlurper()
def resultMap = slurper.parseText(responseText)
def token = resultMap["token"]
return token
} catch(Exception e){
echo "Exception: ${e}"
error "Failed to get a token"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment