Jenkins,主机 key 验证失败,脚本返回退出代码 255

标签 jenkins ssh jenkins-pipeline

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

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

但是每次我添加另一台服务器时都很难添加它,因为我在新服务器中设置了授权 key 并且在命令行中有效,但在 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

最佳答案

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

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

关于Jenkins,主机 key 验证失败,脚本返回退出代码 255,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47608849/

相关文章:

jenkins - 如何将参数传递给 Hudson 作业的 shell 命令

git - Jenkins - Git 子模块凭据与父 repo 不同

jenkins - 使用@GrabConfig时找不到合适的类加载器可供抓取

Git 子模块在使用 SSH 的 TFS 构建上失败

session - Jsch 0.1.54 session.connect() throws com.jcraft.jsch.JSchException : Session. connect : java. io.IOException: End of IO Stream Read

jenkins - 如何访问groovy类文件中的全局变量?

logging - 是否可以在 Jenkins 管道控制台输出中禁用 [Pipeline] 消息?

jenkins - 如何在 Jenkins 中触发构建之前等待用户提示

github - 如何将 Jenkins GitHub 组织文件夹与受 github 保护的分支一起使用?

ruby - 如何通过 SSH 交互 Session