I'm building a CI flow for my project, according to the official tutorial mentioned here
Build a Node.js and React app with npm .
There some key points in my flow:
jenkins-generated-ssh-key
. I have committed it to GitLab ssh settings.The file content:
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'
}
}
}
}
}
The 'Build' stage contains git committing and tagging steps. All stuffs for pushing tag are ready.
Every time in performing 'Deploy' stage, the sshagent will get killed before pushing git tags.
[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.
I have tried adjusting the Jenkinsfile many times, and I found that if the step is 'git push' or 'ssh -T git@git.xxx', it won't get the ssh-agent wrapping the inner steps. Then I get the permission denied. The ssh-agent always get killed before doing ssh connection but will wrap other steps, which don't require ssh auth, normally.
Host key verification failed.fatal: Could not read from remote repository.
To resolve the above error, we need to manually ssh once or use this parameter
StrictHostKeyChecking=no
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.