Skip to content

Instantly share code, notes, and snippets.

@w8r
Created May 28, 2018 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w8r/d68bd77e41339034ed73e11b4c8c535f to your computer and use it in GitHub Desktop.
Save w8r/d68bd77e41339034ed73e11b4c8c535f to your computer and use it in GitHub Desktop.
Ensure SSH keys in Jenkins slave
pipeline {
agent { dockerfile true }
environment {
npm_config_cache = 'npm-cache'
}
stages {
stage('Install') {
steps {
echo 'Ensure SSH keys'
// set the credentials to be able to access private repos
withCredentials([file(credentialsId: 'sshkey', variable: 'SSHKEY')]) {
sh 'mkdir -p ~/.ssh'
sh 'cp $SSHKEY ~/.ssh/id_rsa'
sh 'chmod 600 ~/.ssh/id_rsa'
sh 'echo \'Host github.com\n StrictHostKeyChecking no\' > ~/.ssh/config'
}
echo 'Install'
sh 'node --version'
sh 'npm --version'
sh 'npm i'
}
}
stage('Unit tests') {
steps {
sh 'npm t'
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment