Last active
September 16, 2019 15:47
-
-
Save jvz/b6b1e96af6e1ff4ffbc59237e7bbf50a to your computer and use it in GitHub Desktop.
Example usage of credentials parameters for scripted pipelines
This file contains 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
// 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