[Jenkins][git]構建時提示Caused by: hudson.plugins.git.GitException: Command "/usr/bin/git reset --hard" r

---------------------java

如需轉載,轉載請註明出處。ios

---------------------git

今日發現全部IOS構建相關的job所有失敗,並提示以下錯誤:fetch

ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from http://git.xxxx/ios/xxxx-ios.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:810)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1066)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1097)
    at hudson.scm.SCM.checkout(SCM.java:485)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1269)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:604)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
    at hudson.model.Run.execute(Run.java:1741)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:410)
Caused by: hudson.plugins.git.GitException: Command "/usr/bin/git reset --hard" returned status code 128:
stdout: 
stderr: error: bad signature
fatal: index file corrupt

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1719)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1695)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1691)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1321)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.reset(CliGitAPIImpl.java:372)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.clean(CliGitAPIImpl.java:670)
    at hudson.plugins.git.GitAPI.clean(GitAPI.java:311)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:884)
    at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:859)
    at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:818)
    at hudson.remoting.UserRequest.perform(UserRequest.java:152)
    at hudson.remoting.UserRequest.perform(UserRequest.java:50)
    at hudson.remoting.Request$2.run(Request.java:332)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at hudson.remoting.Engine$1$1.run(Engine.java:85)
    at java.lang.Thread.run(Thread.java:745)
    at ......remote call to qa-ios4-macpro(Native Method)
    at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1416)
    at hudson.remoting.UserResponse.retrieve(UserRequest.java:252)
    at hudson.remoting.Channel.call(Channel.java:781)
    at hudson.remoting.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:249)
    at com.sun.proxy.$Proxy76.clean(Unknown Source)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl.clean(RemoteGitImpl.java:453)
    at hudson.plugins.git.extensions.impl.CleanBeforeCheckout.decorateFetchCommand(CleanBeforeCheckout.java:32)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:806)
    ... 11 more
ERROR: null

解決思路:ui

其實遇到這種問題的緣由有不少,大體以下:spa

1. Linux/Mac的權限問題:確保啓動Jenkins服務的用戶自身有Jenkins所在目錄的權限。(好比用非root用戶權限進行操做)3d

2. 帳號權限問題:確保Job裏選擇的Credentials帳號有權限,GIT對應的SSH配置存在。code

3. 工程目錄損壞問題:在workspace工程目錄下,嘗試git命令是否可用。orm

發現提示:blog

error: bad signature
fatal: index file corrupt

說明:

index file在git中指的是.git/index這個文件。這個文件保存的是暫存區的信息,也就是索引信息。

能夠經過 git ls-files --stage 來查看暫存區的內容。

經過錯誤信息fatal:index file corrupt,能夠看出這個文件已經損壞。 能夠經過git reset來恢復。

解決方法:

1. 進入工程目錄下:/Users/Shared/Jenkins/Home/jenkins/workspace/xxxx-ios/.git

2. 刪除或重命名.git目錄下的index文件:rm -f .git/index或mv .git/index.bak

3. 從新生成index文件:git reset

4. 檢查是否可用:git status

 

再次構建,成功,cheers~

 

 

今日發現,提交代碼後,Jenkins沒有自動構建,進入相應工程目錄後發現:

提示以下:

fatal: index file smaller than expected

 使用本文所寫的方法便可解決。

相關文章
相關標籤/搜索