I am working on a project where the build generates a file that is needed to keep some ids consistent, therefor I need to be able to make a commit and push it to a Bitbucket repo from within the Jenkins declarative pipeline.

My code is as follows:

stage('Generating and committing glyphs.json') {
  when {
    branch 'develop'
  agent {
    docker {
      image 'mhart/alpine-node:10'
  steps {
    unstash 'dist'
    sh 'cp ./dist/.fontcustom-manifest.json .fontcustom-manifest.json'

    sh 'apk --update add git openssh'

    sh 'npm install'
    sh 'npm run update-glyph-index'

    sshagent(credentials: ['bitbucket_ssh']) {
       sh 'git config --global user.email "jenkins@<org>.com"'
       sh 'git config --global user.name "Jenkins"'

       sh 'git remote set-url origin git@bitbucket.org:<org>/<repo>.git'

       sh 'git add ./svg/glyphs.json'
       sh 'git commit -m "Auto-committing glyphs.json"'
       sh 'git push origin develop'

I'm pretty much clueless about anything that has to do with ssh, but I do know my way around a declarative Jenkinsfile a bit. The code above gives the following error:

Error loading key "/var/jenkins_home/workspace/<project>_develop@2@tmp/private_key_<somenumbers>.key": invalid format

Time for questions I guess:

  • Is using the sshagent step the way to go, or should I use withCredentials?
  • Do I add the Proc-Type and DEK-Info parts of the key file to my Jenkins credentials?
  • Is it maybe better to commit my stuff from a js file and just run that? I wouldn't know where to start with authentication from Jenkins, but I have a script that commits and pushes from my pc.
  • I'm assuming private_key_<somenumbers>.key is the bitbucket ssh key? invalid format sounds like you either generated your key incorrectly, or maybe copy/pasted it incorrectly into Jenkins. Can you verify that the key is correct? – PrestonM Aug 15 at 15:03
  • I think it's looking for a file called private_key_<somenumbers>.key... Would this be where jenkins puts my key or something? – Scuba Kay Aug 15 at 17:05
  • Yes. what you need to do is check to make sure that your bitbucket_ssh credential in Jenkins is formatted correctly. – PrestonM Aug 15 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.