Skip to content

Instantly share code, notes, and snippets.

@jvz
Last active November 8, 2019 15:22
Show Gist options
  • Save jvz/9099bef04fc8fbb67ca46cf041ebef8e to your computer and use it in GitHub Desktop.
Save jvz/9099bef04fc8fbb67ca46cf041ebef8e to your computer and use it in GitHub Desktop.
Example usage of credentials parameters in declarative pipelines
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