Jenkins执行git命令报错:Host key verification failed.

Jenkins通过pipeline获取代码的时候,报错stderr: Host key verification failed.
报错日志如下:

[Pipeline] { (获取代码)
[Pipeline] echo
start fetch code from git: ssh://[email protected]:2222/Bruce/ops132.git
[Pipeline] deleteDir
[Pipeline] git
Cloning the remote Git repository
Cloning repository ssh://[email protected]:2222/Bruce/ops132.git
 > git init /var/lib/jenkins/workspace/ops132 # timeout=10
Fetching upstream changes from ssh://[email protected]:2222/Bruce/ops132.git
 > git --version # timeout=10
 > git fetch --tags --progress ssh://[email protected]:2222/Bruce/ops132.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress ssh://[email protected]:2222/Bruce/ops132.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: 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主机上切换到Jenkins用户,执行git命令拉取代码,复现报错,没有权限

  1. 切换到Jenkins用户sudo su -s /bin/bash jenkins
  2. 执行git命名拉取代码git clone ssh://[email protected]:2222/Bruce/ops132.git
    报错没权限
jenkins@ubuntu:~/temp$ git clone ssh://[email protected]:2222/Bruce/ops132.git
Cloning into 'ops132'...
The authenticity of host '[192.168.174.133]:2222 ([192.168.174.133]:2222)' can't be established.
ECDSA key fingerprint is d1:d0:15:64:04:1c:38:e4:96:b9:86:9f:07:e9:1e:2d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.174.133]:2222' (ECDSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

  1. 配置Jenkins用户的ssh key,然后将公钥配置到GitLab就可以了
jenkins@ubuntu:~/temp$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa.
Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub.
The key fingerprint is:
59:fd:95:86:a5:22:a1:e9:9d:d4:39:f5:ad:dc:82:b8 jenkins@ubuntu
The key's randomart image is:
+--[ RSA 2048]----+
|         .   . . |
|        o o.o = o|
|       o o.=.o +o|
|      . ooo.o+.+ |
|       .So. . = .|
|           .   . |
|          E      |
|                 |
|                 |
+-----------------+

  1. 配置
    Jenkins执行git命令报错:Host key verification failed._第1张图片

再次执行构建,验证问题解决

你可能感兴趣的:(Jenkins)