Skip to content

Instantly share code, notes, and snippets.

@jvz
Last active September 16, 2019 15:47
Show Gist options
  • Save jvz/b6b1e96af6e1ff4ffbc59237e7bbf50a to your computer and use it in GitHub Desktop.
Save jvz/b6b1e96af6e1ff4ffbc59237e7bbf50a to your computer and use it in GitHub Desktop.
Example usage of credentials parameters for scripted pipelines
// build parameters can insert user credentials for the entire pipeline
/*
properties([
parameters([
credentials(credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
defaultValue: '',
description: 'Production deployment key',
name: 'deployKey',
required: true)
])
])
*/
node {
stage('Build') {
sh './build.sh'
}
stage('Deploy') {
// alternatively, we can use an input step to insert user credentials when needed
input message: 'Select deployment credentials', parameters: [
credentials(credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
defaultValue: '',
description: 'Production deployment key',
name: 'deployKey',
required: true)
]
withCredentials([
usernameColonPassword(credentialsId: 'deployKey', variable: 'DEPLOY_KEY')
]) {
sh 'curl -u "$DEPLOY_KEY" -XPOST https://webhooks.example.com/promote/'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment