3

I have a building-server where I have Jenkins 2.73.3 and another servers where I deploy my apps.

I have also set up a credential to connect from building-server to the other servers.

But everytime I add another server it is difficult to add it because I set up the authorized key in the new server and in the command line works, but not in Jenkins.

Here is a little recipe that fails:

pipeline {
  agent any

  stages {

    stage('Set conditions') {
      steps {
        sshagent(['xxxx-xxxx-xxxx-xxxx-xxxx']) {
          sh "ssh user@product.company.com 'echo $HOME'"
        }
      }
    }

  }
}

And here is the Log failure:

[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
[check] Running shell script
+ ssh user@product.company.com echo /var/lib/jenkins
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 12567 killed;
[ssh-agent] Stopped.
Host key verification failed.
[Pipeline] }
[Pipeline] // sshagent
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 255
Finished: FAILURE
Gerold Broser
  • 11,355
  • 4
  • 36
  • 85
agusgambina
  • 5,073
  • 14
  • 46
  • 77
  • Possible duplicate of [Jenkins Host key verification failed](https://stackoverflow.com/questions/15174194/jenkins-host-key-verification-failed) – Damon Apr 14 '18 at 20:29

1 Answers1

5

It seems that the solution was to add the parameter StrictHostKeyChecking to the shell script line

sh "ssh -o StrictHostKeyChecking=no user@product.company.com 'echo $HOME'"
agusgambina
  • 5,073
  • 14
  • 46
  • 77
  • 3
    While this will work, this bypasses the verification that the target host is who you want to connect to and is a potential for exploit. You should instead add the target to the build agent's `~/.ssh/known_hosts` file by trying to ssh from each build agent to the target host (or from Jenkins master if not using build agents). See [this answer](https://stackoverflow.com/a/15196114/734790) to [this question](https://stackoverflow.com/questions/15174194/jenkins-host-key-verification-failed) – Damon Apr 14 '18 at 20:28