我有一个 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/