Created
February 23, 2020 22:27
-
-
Save naturalett/af02748785c8aa6051dbb70e0dfa1ca2 to your computer and use it in GitHub Desktop.
getToken
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
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