Skip to content

Instantly share code, notes, and snippets.

@baumato
Created March 30, 2020 16:39
Show Gist options
  • Save baumato/5b8302ad15ece1b80691cdbfbf16fd8a to your computer and use it in GitHub Desktop.
Save baumato/5b8302ad15ece1b80691cdbfbf16fd8a to your computer and use it in GitHub Desktop.
pipeline {
agent any
stages {
stage('usernamePassword') {
steps {
script {
withCredentials([
usernamePassword(credentialsId: 'gitlab',
usernameVariable: 'username',
passwordVariable: 'password')
]) {
print 'username=' + username + 'password=' + password
print 'username.collect { it }=' + username.collect { it }
print 'password.collect { it }=' + password.collect { it }
}
}
}
}
stage('usernameColonPassword') {
steps {
script {
withCredentials([
usernameColonPassword(
credentialsId: 'gitlab',
variable: 'userpass')
]) {
print 'userpass=' + userpass
print 'userpass.collect { it }=' + userpass.collect { it }
}
}
}
}
stage('string (secret text)') {
steps {
script {
withCredentials([
string(
credentialsId: 'joke-of-the-day',
variable: 'joke')
]) {
print 'joke=' + joke
print 'joke.collect { it }=' + joke.collect { it }
}
}
}
}
stage('sshUserPrivateKey') {
steps {
script {
withCredentials([
sshUserPrivateKey(
credentialsId: 'production-bastion',
keyFileVariable: 'keyFile',
passphraseVariable: 'passphrase',
usernameVariable: 'username')
]) {
print 'keyFile=' + keyFile
print 'passphrase=' + passphrase
print 'username=' + username
print 'keyFile.collect { it }=' + keyFile.collect { it }
print 'passphrase.collect { it }=' + passphrase.collect { it }
print 'username.collect { it }=' + username.collect { it }
print 'keyFileContent=' + readFile(keyFile)
}
}
}
}
stage('dockerCert') {
steps {
script {
withCredentials([
dockerCert(
credentialsId: 'production-docker-ee-certificate',
variable: 'DOCKER_CERT_PATH')
]) {
print 'DOCKER_CERT_PATH=' + DOCKER_CERT_PATH
print 'DOCKER_CERT_PATH.collect { it }=' + DOCKER_CERT_PATH.collect { it }
print 'DOCKER_CERT_PATH/ca.pem=' + readFile("$DOCKER_CERT_PATH/ca.pem")
print 'DOCKER_CERT_PATH/cert.pem=' + readFile("$DOCKER_CERT_PATH/cert.pem")
print 'DOCKER_CERT_PATH/key.pem=' + readFile("$DOCKER_CERT_PATH/key.pem")
}
}
}
}
stage('list credentials ids') {
steps {
script {
sh 'cat $JENKINS_HOME/credentials.xml | grep "<id>"'
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment