菜鸟笔记
提升您的技术认知

jenkins添加Git项目时报错Failed to connect to repository : Error performing git command: git ls-remote -h

原因分析:这是由于git客户端版本过低造成的!或者未安装git
Jenkins本机默认使用"yum install -y git" 安装的git版本比较低,应该自行安装更高版本的git。

查看GI版本

git --version

如果存在,卸载低版本

yum remove -y git

1、下载高版本

接着进行git版本升级操作:下载并安装高版本的git,下载地址:https://mirrors.edge.kernel.org/pub/software/scm/git/

[root@localhost ~]# yum -y install libcurl-devel expat-devel curl-devel  gettext-devel openssl-devel zlib-devel

[root@localhost ~]# yum -y install  gcc perl-ExtUtils-MakeMaker

[root@localhost ~]# cd /usr/local/src/

# 下面的地址就是通过之前的下载地址获取的
[root@localhost src]# wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz

[root@localhost src]# tar -zvxf git-2.9.5.tar.gz

[root@localhost src]# cd git-2.9.5.tar

[root@localhost git-2.9.5]# make prefix=/usr/local/git all

[root@localhost git-2.9.5]# make prefix=/usr/local/git install

2、添加git到环境变量

[root@localhost git-2.9.5]# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc

[root@localhost git-2.9.5]# source /etc/bashrc

3、查看更新后的git版本和所在路径

[root@localhost ~]# git --version

[root@localhost ~]# whereis git

4、进入jenkins设置

接着登录jenkins界面,依次打开"系统管理" -> "Global Tool Configuration" 全局工具配置-> "Git" -> "Path to Git executable",在此处填入"whereis git"查询出的地址 + "/bin/git" (如上面"whereis git"的地址为"/usr/local/git",则应该填入 "/usr/local/git/bin/git") 并保存。

最后再在Jenkins新建项目中源码管理Repository URL添加git地址,尝试多刷几次就可以了。