在我的Jenkins管道的其中一个阶段,我做了
stage('SSH into the Server') {
steps {
withCredentials([sshUserPrivateKey(
credentialsId: '<ID>',
keyFileVariable: 'KEY_FILE')]) {
sh '''
cat ${KEY_FILE} > ./key_key.key
eval $(ssh-agent -s)
chmod 600 ./key_key.key
ssh-add ./key_key.key
ssh-add -L
ssh <username>@<server> docker ps
'''
}
}
}
只是简单地通过ssh进入服务器并检查docker ps
。
credentialId
来自我的Jenkins服务器中的Global Credentials
。
但是,在运行此程序时,
我得到了
+ cat ****
++ ssh-agent -s
+ eval 'SSH_AUTH_SOCK=/tmp/ssh-.../agent.57271;' export 'SSH_AUTH_SOCK;' 'SSH_AGENT_PID=57272;' export 'SSH_AGENT_PID;' echo Agent pid '57272;'
++ SSH_AUTH_SOCK=/tmp/ssh-.../agent.57271
++ export SSH_AUTH_SOCK
++ SSH_AGENT_PID=57272
++ export SSH_AGENT_PID
++ echo Agent pid 57272
Agent pid 57272
+ chmod 600 ./key_key.key
+ ssh-add ./key_key.key
然后就失败了,没有更多的消息。
我做错了吗?
发布于 2019-11-26 16:26:48
基于你的意图,我认为这是一种非常复杂的方式。我强烈推荐使用SSH代理插件。
https://jenkins.io/doc/pipeline/steps/ssh-agent/
你可以一步到位。
sshagent (credentials: ['<ID>']) {
sh 'ssh <username>@<server> docker ps'
}
使用与您上面提到的全局凭证相同的UserPrivateKey的credentialsId。
https://stackoverflow.com/questions/59041713
复制相似问题