2

In Jenkins, I have a Credential with an ID, a username, a passphrase and a private key.

In my jenkinsfile I try to use ssh-agent like this :

sshagent(['my_credential_id']) {
  // sh "git something"
}

But it doesn't work and I don't know why.

Do you know how I can debbug it ?

[Pipeline] { ( [first step] )
[Pipeline] sshagent
[ssh-agent] Using credentials [my credential description]
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent]   Exec ssh-agent (binary ssh-agent on a remote machine)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-UZJIW23748/agent.23748
SSH_AGENT_PID=23750
$ ssh-add /app/jenkins-slave/workspace/[project]/[project]@tmp/private_key_[XXXXXXXXXXXXXX].key
ssh_askpass: exec(/app/jenkins-slave/workspace/[project]/[project]@tmp/askpass_[XXXXXXXXXXXXXX].sh): No such file or directory
[Pipeline] // sshagent
[Pipeline] End of Pipeline
ERROR: Failed to run ssh-add
Taeith
  • 51
  • 1
  • 7
  • `Failed to run ssh-add`. Are you able to run `ssh-add` manually? As a Jenkins user? Without TTY? If there's a passphrase, `ssh-add` should ask for it. – MaratC Feb 13 '20 at 08:28
  • If you're running on linux/max: does your Jenkins user have a login shell? I'm curious if a missing login shell would prevent these types of operations. – jonni83 Sep 06 '22 at 17:13

1 Answers1

1

In my experience there is something wrong with your private key.

Save the private key to a file, e.g. privatekey.txt and test it out like so:

$ ssh -o StrictHostKeyChecking=no -i privatekey.txt username@hostname.example.com
Beoski
  • 71
  • 6