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

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

[Pipeline] { (获取代码)
[Pipeline] echo
start fetch code from git: ssh://git@192.168.174.133:2222/Bruce/ops132.git
[Pipeline] deleteDir
[Pipeline] git
Cloning the remote Git repository
Cloning repository ssh://git@192.168.174.133:2222/Bruce/ops132.git
 > git init /var/lib/jenkins/workspace/ops132 # timeout=10
Fetching upstream changes from ssh://git@192.168.174.133:2222/Bruce/ops132.git
 > git --version # timeout=10
 > git fetch --tags --progress ssh://git@192.168.174.133: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://git@192.168.174.133: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://git@192.168.174.133:2222/Bruce/ops132.git
    报错没权限
jenkins@ubuntu:~/temp$ git clone ssh://git@192.168.174.133: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. 配置
    在这里插入图片描述

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

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 当你在使用Jenkins创建Git的pipeline时,如果遇到了"stderr: Host key verification failed."错误,这通常是由于SSH验证方式导致的。在填写Git Repo时,你使用了SSH验证方式,但是你的证书没有传到对方的授权登录主机列表中,所以无法成功登录远程主机。解决这个问题的方法是,使用Jenkins用户创建的秘钥来访问GitLab。之前你可能使用了root用户生成的秘钥,在命令执行时,因为是root用户登录环境,所以可以正常进行Git clone操作。但是在Jenkins环境中执行Git操作时,由于没有找到Jenkins用户的公钥,导致无法进行免密访问。\[1\]\[2\] #### 引用[.reference_title] - *1* [jenkins stderr: Host key verification failed.](https://blog.csdn.net/qq_28035571/article/details/79473699)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Jenkins设置Git源问题-stderr: Host key verification failed.](https://blog.csdn.net/bigwood99/article/details/107073603)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值