Skip to content

Instantly share code, notes, and snippets.

@adampats
Created July 27, 2016 05:00
Show Gist options
  • Save adampats/b0c37de0f684e14c5897ddf1cb889f63 to your computer and use it in GitHub Desktop.
Save adampats/b0c37de0f684e14c5897ddf1cb889f63 to your computer and use it in GitHub Desktop.
Jenkins Credentials Binding pipeline groovy
try {
err = null
currentBuild.result = "SUCCESS"
node {
stage 'One'
// using a single secret Jenkins credential
withCredentials([[$class: 'StringBinding', credentialsId: 'my-api-token', variable: 'API_TOKEN']]) {
sh '''
set +x
echo '$API_TOKEN (should be masked by Jenkins UI as ***): ' "$API_TOKEN"
'''
}
}
} catch (caughtError) {
err = caughtError
currentBuild.result = "FAILURE"
} finally {
if (err) {
throw err
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment