Anand
Anand

Reputation: 201

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

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?

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$2.invoke(GitSCM.java:1005)
	at hudson.plugins.git.GitSCM$2.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$2.invoke(GitSCM.java:1064)
	at hudson.plugins.git.GitSCM$2.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$2.invoke(GitSCM.java:1076)
	at hudson.plugins.git.GitSCM$2.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)

Upvotes: 16

Views: 26716

Answers (6)

Ishan Hettiarachchi
Ishan Hettiarachchi

Reputation: 1704

I got the same error after upgrading the Java version. The solution was to disconnect and relaunch the Jenkins node. Until it was done the Java environment was set to the previous (uninstalled) version.

Upvotes: 0

Khalil Maatoug
Khalil Maatoug

Reputation: 11

I had the same error, You should install git in your Jenkins instance (EC2)

Ubuntu:

sudo apt install git -y

Redhat:

sudo dnf install git -y

Upvotes: 0

papigee
papigee

Reputation: 7368

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 .git directory.

Run your job again.

Upvotes: 4

Jitender Kumar
Jitender Kumar

Reputation: 2587

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

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

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

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.

Upvotes: 2

Anand
Anand

Reputation: 201

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.

Upvotes: 4

VonC
VonC

Reputation: 1322795

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

See for example this answer:

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

Upvotes: 1

Related Questions