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",如下圖:

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

查看jenkins本機的git版本

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

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

[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/

[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到環境變量

[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版本和所在路徑

[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") 並保存。

最后再在Jenkins新建項目中源碼管理Repository URL添加git地址,嘗試多刷幾次就可以了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM