Jenkins新建項目中源碼管理Repository URL使用Git報錯:Failed to connect to repository : Command "git ls-remote -h...

 

以前部署了Gitlab+Gerrit+Jenkins持續集成環境,但在Jenkins中新建項目的源碼管理"Repository URL"中添加git地址環節出現了問題,信息爲"Failed to connect to repository : Error performing command: git ls-remote -h http://×××××××××.git HEAD",以下圖:node

緣由分析:這是因爲git客戶端版本太低形成的!
Jenkins本機默認使用"yum install -y git" 安裝的git版本比較低,應該自行安裝更高版本的git。git

查看jenkins本機的git版本bash

[root@jenkins ~]# git --version
git version 1.7.1

卸載本機低版本的git,自行安裝更高版本的gitcurl

[root@jenkins ~]# yum remove -y git            //或者使用"rpm -e --nodeps git"命令進行卸載
[root@jenkins ~]# git --version    
-bash: /usr/bin/git: No such file or directory

接着進行git版本升級操做:下載並安裝高版本的git,下載地址:https://mirrors.edge.kernel.org/pub/software/scm/git/url

[root@jenkins ~]# yum -y install libcurl-devel expat-devel curl-devel  gettext-devel openssl-devel zlib-devel
[root@jenkins ~]# yum -y install  gcc perl-ExtUtils-MakeMaker
[root@jenkins ~]# cd /usr/local/src/
[root@jenkins src]# wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.1.1.tar.gz
[root@jenkins src]# tar -zvxf git-2.1.1.tar.gz 
[root@jenkins src]# cd git-2.1.1
[root@jenkins git-2.1.1]# make prefix=/usr/local/git all
[root@jenkins git-2.1.1]# make prefix=/usr/local/git install

添加git到環境變量spa

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

查看更新後的git版本和所在路徑orm

[root@jenkins ~]# git --version
git version 2.1.1
[root@jenkins ~]# whereis git
git: /usr/local/git

接着登陸jenkins界面,依次打開"系統管理" -> "系統設置" -> "Git" -> "Path to Git executable",在此處填入"whereis git"查詢出的地址 + "/bin/git" (如上面"whereis git"的地址爲"/usr/local/git",則應該填入 "/usr/local/git/bin/git") 並保存。blog

最後再在Jenkins新建項目中源碼管理Repository URL添加git地址,嘗試多刷幾回就能夠了。ssl

相關文章
相關標籤/搜索