1. 程式人生 > >解決Jenkins上git出現的“ERROR: Error fetching remote repo 'origin'”問題

解決Jenkins上git出現的“ERROR: Error fetching remote repo 'origin'”問題

解決 ble after upan 第一時間 building finish als -i

這兩天在搭建Jenkins環境,在構建新job時報ERROR: Error fetching remote repo ‘origin‘,具體錯誤如下:

Started by user wupan
Building in workspace /root/.jenkins/workspace/deploy
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url {url} # timeout=10
Fetching upstream changes from {url}
 > git --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git fetch --tags --progress {url} +refs/heads/*:refs/remotes/origin/*
ERROR: Timeout after 10 minutes
ERROR: Error fetching remote repo ‘origin‘
hudson.plugins.git.GitException: Failed to fetch from {url}
	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:888)
	at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1155)
	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1186)
	at hudson.scm.SCM.checkout(SCM.java:504)
	at hudson.model.AbstractProject.checkout(AbstractProject.java:1208)
	at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:574)
	at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:499)
	at hudson.model.Run.execute(Run.java:1727)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress {url} +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: remote: Counting objects: 62, done.        
remote: Compressing objects:   4% (1/23)           
remote: Compressing objects:   8% (2/23)           
remote: Compressing objects:  13% (3/23)           
remote: Compressing objects:  17% (4/23)           
remote: Compressing objects:  21% (5/23)           
remote: Compressing objects:  26% (6/23)           
remote: Compressing objects:  30% (7/23)           
remote: Compressing objects:  34% (8/23)           
remote: Compressing objects:  39% (9/23)           
remote: Compressing objects:  43% (10/23)           
remote: Compressing objects:  47% (11/23)           
remote: Compressing objects:  52% (12/23)           
remote: Compressing objects:  56% (13/23)           
remote: Compressing objects:  60% (14/23)           
remote: Compressing objects:  65% (15/23)           
remote: Compressing objects:  69% (16/23)           
remote: Compressing objects:  73% (17/23)           
remote: Compressing objects:  78% (18/23)           
remote: Compressing objects:  82% (19/23)           
remote: Compressing objects:  86% (20/23)           
remote: Compressing objects:  91% (21/23)           
remote: Compressing objects:  95% (22/23)           
remote: Compressing objects: 100% (23/23)           
remote: Compressing objects: 100% (23/23), done.        
error: unpack-objects died of signal 15
fatal: unpack-objects failed

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2002)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1721)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:72)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:405)
	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:886)
	... 11 more
ERROR: Error fetching remote repo ‘origin‘
Finished: FAILURE

遇到問題後,開始了漫長的百度,有網友提供了下面幾個解決的思路。

解決思路:

1、第一時間發現應該是權限問題,那麽可以切換成git協議或者https的協議去獲取。

2、如果不是協議的問題,看是不是git的路徑錯了導致的,再次配置節點的機器上的git路徑。

3、如果是linux的機器,就要去確定是不是SSH的key導致的,而且用ssh去連接git,那麽就要去配置ssh的key,這一點比較復雜也很重要。

解決方案:

一、權限問題導致

1、配置Jenkins的Git環境

Name:Git用戶名,我配置的是GitHub的用戶名,大家可以試試其他的

Path to Git executable:Git安裝路徑(Linux命令:which git、windows 命令: where git)

技術分享圖片

2、把私鑰拷貝到git配置中

在源碼管理中,點擊Add,添加秘鑰

技術分享圖片

Repository URL:git代碼地址

Credentials:秘鑰

技術分享圖片

Kind:選擇SSH Username with private key

Username:隨便填寫

Private Key:選擇Enter directly

Key:系統生成的git id_rsa中的Key

2)輸入完成後點擊保存,源碼管理中填寫

Repository URL:git代碼地址

Credentials:秘鑰(選擇剛才填寫的UserName)

3)點擊保存,重新構建Job,結果成功

二、將url改成http://用戶名:密碼@ip/的格式,git配置改成不使用密碼(網友提供色解決方案未嘗試,大家可以去試試)

如果有問題,可以在下面評論,謝謝

解決Jenkins上git出現的“ERROR: Error fetching remote repo 'origin'”問題