【问题标题】:Jenkins, Host key verification failed, script returned exit code 255Jenkins,主机密钥验证失败,脚本返回退出代码 255
【发布时间】:2018-05-16 11:18:58
【问题描述】:

我有一个 building-server,我有 Jenkins 2.73.3 和另一个服务器,我在其中部署我的应用程序。

我还设置了从building-server 连接到其他服务器的凭据。

但是每次我添加另一个服务器时都很难添加它,因为我在新服务器中设置了授权密钥,并且在命令行中有效,但在 Jenkins 中没有。

这是一个失败的小食谱:

pipeline {
  agent any

  stages {

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

  }
}

这是日志失败:

[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

【问题讨论】:

标签: jenkins ssh jenkins-pipeline


【解决方案1】:

看来解决方案是在shell脚本行中添加参数StrictHostKeyChecking

sh "ssh -o StrictHostKeyChecking=no user@product.company.com 'echo $HOME'"

【讨论】:

  • 虽然这会起作用,但这会绕过验证目标主机是您想要连接的主机并且是潜在的攻击者。您应该将目标添加到构建代理的 ~/.ssh/known_hosts 文件中,方法是尝试从每个构建代理 ssh 到目标主机(如果不使用构建代理,则从 Jenkins 主机)。请参阅this answerthis question
猜你喜欢
  • 2013-02-16
  • 1970-01-01
  • 2019-08-27
  • 1970-01-01
  • 2017-09-10
  • 1970-01-01
  • 2016-02-28
  • 1970-01-01
  • 2021-12-25
相关资源
最近更新 更多