Jenkins,主机密钥验证失败,脚本返回退出代码255
我有一个Jenkins,主机密钥验证失败,脚本返回退出代码255,jenkins,ssh,jenkins-pipeline,Jenkins,Ssh,Jenkins Pipeline,我有一个构建服务器,在那里我有Jenkins 2.73.3和另一个服务器,我在那里部署我的应用程序 我还设置了一个凭据以从building server连接到其他服务器 但每次我添加另一台服务器时,都很难添加它,因为我在新服务器和命令行中设置了授权密钥,但在Jenkins中没有设置 以下是一个失败的小秘诀: pipeline { agent any stages { stage('Set conditions') { steps { sshagen
构建服务器
,在那里我有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
似乎解决方案是将参数StrictHostKeyChecking添加到shell脚本行
sh "ssh -o StrictHostKeyChecking=no user@product.company.com 'echo $HOME'"
虽然这会起作用,但这会绕过验证,即目标主机是您要连接的主机,并且可能会被利用。相反,您应该通过尝试从每个生成代理到目标主机(或者从Jenkins master,如果不使用生成代理),将目标添加到生成代理的
~/.ssh/known_hosts
文件中。注意可能的重复