Last active
November 8, 2019 15:22
-
-
Save jvz/9099bef04fc8fbb67ca46cf041ebef8e to your computer and use it in GitHub Desktop.
Example usage of credentials parameters in declarative 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
pipeline { | |
agent any | |
// user credentials as build parameters | |
/* | |
parameters { | |
credentials(credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl', | |
defaultValue: '', | |
description: 'Production deployment key', | |
name: 'deployKey', | |
required: true) | |
} | |
*/ | |
stages { | |
stage('Build') { | |
steps { | |
sh './build.sh' | |
} | |
} | |
stage('Deploy') { | |
// user credentials as an input step (doesn't prompt for credentials until executing this stage) | |
input { | |
message 'Select deployment credentials' | |
parameters { | |
credentials(credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl', | |
defaultValue: '', | |
description: 'Production deployment key', | |
name: 'deployKey', | |
required: true) | |
} | |
} | |
environment { | |
DEPLOY_KEY = credentials('deployKey') | |
} | |
steps { | |
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