Skip to content

Instantly share code, notes, and snippets.

@InTheCloudDan
Last active February 28, 2018 17:42
Show Gist options
  • Save InTheCloudDan/84f4bca4068ed7b04692c5e9b9b63921 to your computer and use it in GitHub Desktop.
Save InTheCloudDan/84f4bca4068ed7b04692c5e9b9b63921 to your computer and use it in GitHub Desktop.
@NonCPS
def call(String repository, String credentials) {
//withCredentials([usernamePassword(credentialsId: credentials,
// usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: credentials.toString(), passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME']]) {
println env.USERNAME
println env.PASSWORD
sh 'echo $USERNAME and $PASSWORD'
def authString = "${env.USERNAME}:${env.PASSWORD}".encodeBase64().toString();
URLConnection conn = new URL("https://api.${githubUrl}.com/repos/${repository}/releases/latest").openConnection();
conn.setRequestProperty("Authorization", "Basic ${authString}")
def releases = new groovy.json.JsonSlurper().parse(new BufferedReader(new InputStreamReader(conn.getInputStream())));
releases.each {
println it.name
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment