根据这里提到的官方教程,我正在为我的项目构建CI流程
Build a Node.js and React app with npm
我的流程中有一些关键点:
jenkins-generated-ssh-key
。我已将它提交给GitLab ssh设置。文件内容:
pipeline {
agent { docker 'node:6' }
stages {
stage('Build') {
steps {
sh 'npm run test'
sh 'npm run build'
}
}
stage('Deploy') {
steps {
sshagent (credentials: ['jenkins-generated-ssh-key']) {
sh 'git push --tags'
}
}
}
}
}
'Build'阶段包含git提交和标记步骤。推送标签的所有东西都准备好了。
每次执行'Deploy'阶段时,sshagent都会在推送git标签之前被杀死。
[Pipeline] sshagent
[ssh-agent] Using credentials fe (jenkins-generated-ssh-key)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent] Exec ssh-agent (binary ssh-agent on a remote machine)
$ docker exec d2ba3af75c0e5826d3d00676ebba523117a541d9015ee77c74106862d2665025 env ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-dewb3KyPiizc/agent.130
SSH_AGENT_PID=134
$ docker exec d2ba3af75c0e5826d3d00676ebba523117a541d9015ee77c74106862d2665025 env SSH_AGENT_PID=134 SSH_AUTH_SOCK=/tmp/ssh-dewb3KyPiizc/agent.130 ssh-add /var/jenkins_home/workspace/achilles_master-GZG6BNOXJZHXAGELOPVE2O57MTLCFCSFEEMQVJOWKHCSAQDCMS4Q@tmp/private_key_838589255993535437.key
Identity added: /var/jenkins_home/workspace/achilles_master-GZG6BNOXJZHXAGELOPVE2O57MTLCFCSFEEMQVJOWKHCSAQDCMS4Q@tmp/private_key_838589255993535437.key (rsa w/o comment)
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
$ docker exec d2ba3af75c0e5826d3d00676ebba523117a541d9015ee77c74106862d2665025 env SSH_AGENT_PID=134 SSH_AUTH_SOCK=/tmp/ssh-dewb3KyPiizc/agent.130 ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 134 killed;
[ssh-agent] Stopped.
[achilles_master-GZG6BNOXJZHXAGELOPVE2O57MTLCFCSFEEMQVJOWKHCSAQDCMS4Q] Running shell script
+ git push --tags
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我尝试过多次调整Jenkins文件,我发现如果步骤是'git push'或'ssh -T git@git.xxx',它将不会让ssh-agent包含内部步骤。然后我得到了许可被拒绝。在执行ssh连接之前,ssh-agent总是被杀死,但是通常会包装其他步骤,这些步骤不需要ssh auth。
答案 0 :(得分:0)
主机密钥验证失败。致命:无法从远程读取 存储库。
要解决以上错误,我们需要手动ssh一次或使用此参数
StrictHostKeyChecking =否