8

I am new to Jenkinsfile. I have previously configured my Jenkins job from GUI, and we are now upgrading our server to use Jenkinsfile. My job contains a section which needs to SSH to another server. To do this, I previously used the sshagent plugin on the GUI to specify my keys. However, on the jenkinsfile mechanism this does not work.

First things first: Aside from using jenkinsfile, we have also trasitioned to building in docker. I read in some places that docker might conflict with sshagent plugin, so I am trying to remove docker by starting a clean job with "agent any" and trying to test.

So my new job looks like this:

    @NonCPS  // Necessary to allow .each to work.
def changelist() {
    def changes = ""
    currentBuild.changeSets.each { set ->
        set.each { entry ->
            changes += "${entry.author.id} "
        }
    }
    changes
}

pipeline {
    agent none
    stages {
            stage('test') {
            agent any
            steps {
                sshagent ( ['a-jenkins-credential']) {
    sh '''
ssh -vv myuser@myserver echo testing connection || true
ssh-add -L
echo done running remote windows test
'''
  }
            }
        }


}
}

On the same server, but using the jenkins GUI, this works flawlessly, but on the jenkinsfile pipeline this produces:

FATAL: [ssh-agent] Could not find specified credentials

and proceeds run and fail on the ssh command. The funny thing is, that this job uses the exact same key to succesfully pull from GIT, so it's not like it's not installed on the server.

eshalev
  • 281
  • 1
  • 2
  • 6

1 Answers1

10

Found the problem:

I was using the human readable key name from the GUI. Need to use the key's UUId ID instead (this is specified next to the name in credentials screen)

steps {
            sshagent ( ['THIS-SHOULD-HAVE-BEEN-A-UNIQUE-ID-INSTEAD-OF-A-NAME']) {
eshalev
  • 281
  • 1
  • 2
  • 6