agu*_*ina 3 ssh jenkins jenkins-pipeline
我有一个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'"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是日志失败:
[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
Run Code Online (Sandbox Code Playgroud)
似乎解决方案是将参数 StrictHostKeyChecking 添加到 shell 脚本行
sh "ssh -o StrictHostKeyChecking=no user@product.company.com 'echo $HOME'"
Run Code Online (Sandbox Code Playgroud)