Skip to content

Instantly share code, notes, and snippets.

@rcbop
Created July 30, 2018 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcbop/e2044c31daf17bb41ed37ba3c93abbaa to your computer and use it in GitHub Desktop.
Save rcbop/e2044c31daf17bb41ed37ba3c93abbaa to your computer and use it in GitHub Desktop.
bind ssh private key and use it in a jenkinsfile example
node('node-label'){
stage('Deploy') {
withCredentials([[$class: 'SSHUserPrivateKeyBinding', credentialsId: "1dc9ca1e-a461-40c2-8478-969c66bea0b6", keyFileVariable: 'SSH_PRIVATE_KEY', passphraseVariable: '', usernameVariable: 'SSH_USERNAME']]){
sh "ssh-agent /bin/bash"
sh """
eval \$(ssh-agent) && ssh-add ${SSH_PRIVATE_KEY} && ssh-add -l &&
ENVIRONMENT=${env.ENVIRONMENT} \
PLAYBOOK=${env.PLAYBOOK} \
BASTION_USER=${env.BASTION_USER} \
BASTION_HOST=${env.BASTION_HOST} \
./deploy-ansible.sh
"""
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment