错误:工作区有一个 .git 存储库,但它似乎已损坏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29456583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:52:15  来源:igfitidea点击:

ERROR: Workspace has a .git repository, but it appears to be corrupt

gitjenkinsrepositoryjenkins-pluginscorrupt

提问by Anand

I am not able to pull the code from Github through jenkins. I did try to switch the git plugins in jenkins but it didn't work. No idea what the issue is..Some pointers for this would be helpful.. Am i missing some plugins or ami using plugins with the wrong version?

我无法通过 jenkins 从 Github 中提取代码。我确实尝试在 jenkins 中切换 git 插件,但没有奏效。不知道问题是什么..一些关于这方面的指针会有所帮助..我是否缺少一些插件或我使用了错误版本的插件?

Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/TestGitCon/workspace
Checkout:workspace / /var/lib/jenkins/jobs/TestGitCon/workspace - hudson.remoting.LocalChannel@37ff3f85
Using strategy: Default
ERROR: Workspace has a .git repository, but it appears to be corrupt.
hudson.plugins.git.GitException: Error performing command: usr/bin/git rev-parse --verify HEAD
 at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:904)
 at hudson.plugins.git.GitAPI.launchCommand(GitAPI.java:858)
 at hudson.plugins.git.GitAPI.launchCommand(GitAPI.java:868)
 at hudson.plugins.git.GitAPI.validateRevision(GitAPI.java:326)
 at hudson.plugins.git.GitAPI.hasGitRepo(GitAPI.java:125)
 at hudson.plugins.git.GitSCM.invoke(GitSCM.java:1005)
 at hudson.plugins.git.GitSCM.invoke(GitSCM.java:986)
 at hudson.FilePath.act(FilePath.java:981)
 at hudson.FilePath.act(FilePath.java:959)
 at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:986)
 at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1142)
 at hudson.model.AbstractProject.checkout(AbstractProject.java:1265)
 at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:622)
 at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
 at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:528)
 at hudson.model.Run.execute(Run.java:1759)
 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
 at hudson.model.ResourceController.execute(ResourceController.java:89)
 at hudson.model.Executor.run(Executor.java:240)
Caused by: java.io.IOException: Cannot run program "usr/bin/git" (in directory "/var/lib/jenkins/jobs/TestGitCon/workspace"): error=2, No such file or directory
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
 at hudson.Proc$LocalProc.<init>(Proc.java:244)
 at hudson.Proc$LocalProc.<init>(Proc.java:216)
 at hudson.Launcher$LocalLauncher.launch(Launcher.java:803)
 at hudson.Launcher$ProcStarter.start(Launcher.java:381)
 at hudson.Launcher$ProcStarter.join(Launcher.java:388)
 at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:885)
 ... 18 more
Caused by: java.io.IOException: error=2, No such file or directory
 at java.lang.UNIXProcess.forkAndExec(Native Method)
 at java.lang.UNIXProcess.<init>(UNIXProcess.java:186)
 at java.lang.ProcessImpl.start(ProcessImpl.java:130)
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
 ... 24 more
Cloning the remote Git repository
Cloning repository [email protected]:RosettaCommons/main.git
Error trying to determine the git version: Error performing command: usr/bin/git --version
Assuming 1.6
Fetching upstream changes from [email protected]:RosettaCommons/main.git
ERROR: Problem fetching from origin / origin - could be unavailable. Continuing anyway.
hudson.plugins.git.GitException: Error performing command: usr/bin/git fetch -t [email protected]:RosettaCommons/main.git +refs/heads/*:refs/remotes/origin/*
 at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:904)
 at hudson.plugins.git.GitAPI.launchCommand(GitAPI.java:858)
 at hudson.plugins.git.GitAPI.fetch(GitAPI.java:200)
 at hudson.plugins.git.GitAPI.fetch(GitAPI.java:1105)
 at hudson.plugins.git.GitSCM.invoke(GitSCM.java:1064)
 at hudson.plugins.git.GitSCM.invoke(GitSCM.java:986)
 at hudson.FilePath.act(FilePath.java:981)
 at hudson.FilePath.act(FilePath.java:959)
 at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:986)
 at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1142)
 at hudson.model.AbstractProject.checkout(AbstractProject.java:1265)
 at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:622)
 at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
 at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:528)
 at hudson.model.Run.execute(Run.java:1759)
 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
 at hudson.model.ResourceController.execute(ResourceController.java:89)
 at hudson.model.Executor.run(Executor.java:240)
Caused by: java.io.IOException: Cannot run program "usr/bin/git" (in directory "/var/lib/jenkins/jobs/TestGitCon/workspace"): error=2, No such file or directory
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
 at hudson.Proc$LocalProc.<init>(Proc.java:244)
 at hudson.Proc$LocalProc.<init>(Proc.java:216)
 at hudson.Launcher$LocalLauncher.launch(Launcher.java:803)
 at hudson.Launcher$ProcStarter.start(Launcher.java:381)
 at hudson.Launcher$ProcStarter.join(Launcher.java:388)
 at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:885)
 ... 17 more
Caused by: java.io.IOException: error=2, No such file or directory
 at java.lang.UNIXProcess.forkAndExec(Native Method)
 at java.lang.UNIXProcess.<init>(UNIXProcess.java:186)
 at java.lang.ProcessImpl.start(ProcessImpl.java:130)
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
 ... 23 more
ERROR: Could not fetch from any repository
FATAL: Could not fetch from any repository
hudson.plugins.git.GitException: Could not fetch from any repository
 at hudson.plugins.git.GitSCM.invoke(GitSCM.java:1076)
 at hudson.plugins.git.GitSCM.invoke(GitSCM.java:986)
 at hudson.FilePath.act(FilePath.java:981)
 at hudson.FilePath.act(FilePath.java:959)
 at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:986)
 at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1142)
 at hudson.model.AbstractProject.checkout(AbstractProject.java:1265)
 at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:622)
 at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
 at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:528)
 at hudson.model.Run.execute(Run.java:1759)
 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
 at hudson.model.ResourceController.execute(ResourceController.java:89)
 at hudson.model.Executor.run(Executor.java:240)

回答by Anand

My path to git executable was var/lib/jenkins. I added a slash before var/lib/jenkins, that is, /var/lib/jenkins. Also I installed "Git pull request builder" plugin. I downgraded git plugin version to 1.1.26. Now I can download the code from github through jenkins.

我的 git 可执行文件路径是 var/lib/jenkins。我在var/lib/jenkins前加了一个斜线,也就是/var/lib/jenkins。我还安装了“Git pull request builder”插件。我将 git 插件版本降级到 1.1.26。现在我可以通过jenkins从github下载代码了。

回答by Jitender Kumar

I had the same error, but in my case the reason was different. Actually, I had used curl command in a shell script file and then I had to create a Docker image out it. So to make the Docker image able to execute the curl command I had to install the Curl. And I had written the below code in Docker file

我有同样的错误,但就我而言,原因不同。实际上,我在 shell 脚本文件中使用了 curl 命令,然后我必须创建一个 Docker 镜像。所以为了让 Docker 镜像能够执行 curl 命令,我必须安装 Curl。我在 Docker 文件中编写了以下代码

RUN apt-get update && \
apt-get install -y curl && \

But when I committed my code, the Jenkins build got failed with the same message ERROR: Workspace has a .git repository, but it appears to be corrupt

但是当我提交我的代码时,Jenkins 构建失败并显示相同的消息错误:工作区有一个 .git 存储库,但它似乎已损坏

And the fix was that I had to add --no-install-recommendsin the install curl command. Like this

解决方法是我必须添加--no-install-recommendsinstall curl 命令。像这样

RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \

The reason for that is Ubuntu installs recommended but not suggested packages. So, Ubuntu was trying to add some unwanted but maybe, recommended package which somehow was failing the build.

原因是Ubuntu 安装了推荐但不推荐的包。因此,Ubuntu 试图添加一些不需要但可能推荐的包,但以某种方式导致构建失败。

回答by papigee

To fix this, locate a /jenkins/workspace/<job name>directory in your Jenkins slave (or server). You should either delete all files in the workspace (if there is no negative implication of doing so) or delete only the .gitdirectory.

要解决此问题,请/jenkins/workspace/<job name>在您的 Jenkins 从站(或服务器)中找到一个目录。您应该删除工作区中的所有文件(如果这样做没有负面影响)或仅删除.git目录。

Run your job again.

再次运行你的工作。

回答by VonC

Start checking the location you set for the git tool in the Jenkins settings (Jenkins -> Manage Jenkins -> Configure System).

开始检查您在 Jenkins 设置(Jenkins -> 管理 Jenkins -> 配置系统)中为 git 工具设置的位置。

See for example this answer:

例如,请参阅此答案

Looks like there was problem in GIT configuration of Jenkins, gave full path of GIT instead of only "git"

看起来 Jenkins 的 GIT 配置有问题,给出了 GIT 的完整路径,而不仅仅是“ git