Tuesday, February 15, 2011

Git clone error on Jenkins/Hudson on Windows

Recently I set up a new instance of Jenkins (formerly Hudson) running on my Windows 7 desktop computer. I tried to set up a job that would pull from a GitHub repository and do a build but (like every other time I've tried this) was foiled by the job simply hanging at the step where it tries to clone or fetch from GitHub. Cancelling the job leads to the following errors in the console output:

Started by user cgdecker
Checkout:workspace / E:\Colin\.hudson\jobs\temp\workspace - hudson.remoting.LocalChannel@692769e1
Using strategy: Default
Checkout:workspace / E:\Colin\.hudson\jobs\temp\workspace - hudson.remoting.LocalChannel@692769e1
GitAPI created
Cloning the remote Git repository
Cloning repository origin
$ git clone -o origin git@github.com:cgdecker/jdbc-persist.git E:\Colin\.hudson\jobs\temp\workspace
ERROR: Error cloning remote repo 'origin' : Could not clone git@github.com:cgdecker/jdbc-persist.git
ERROR: Cause: Error performing git clone -o origin git@github.com:cgdecker/jdbc-persist.git E:\Colin\.hudson\jobs\temp\workspace
null
Trying next repository
ERROR: Could not clone repository
FATAL: Could not clone
hudson.plugins.git.GitException: Could not clone
 at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:809)
 at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:740)
 at hudson.FilePath.act(FilePath.java:756)
 at hudson.FilePath.act(FilePath.java:738)
 at hudson.plugins.git.GitSCM.checkout(GitSCM.java:740)
 at hudson.model.AbstractProject.checkout(AbstractProject.java:1171)
 at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:499)
 at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:415)
 at hudson.model.Run.run(Run.java:1362)
 at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:405)
 at hudson.model.ResourceController.execute(ResourceController.java:88)
 at hudson.model.Executor.run(Executor.java:145)

First, I tried the usual suspects:

  • Ensuring that Jenkins was running as the correct user.
  • Ensuring that the user's .ssh directory and keys were in place and checked out.
  • Trying the full path to git.exe in Git's bin directory rather than just using git as the path.

I did a search for the error, but as in the past it turned up no solutions that actually fixed the problem for me. I then tried running a job that just executed a Windows batch command to run git clone on the same repository... which worked fine!

The solution

Double-checking things, I noticed that my PATH contained two directories for my Git installation (msysgit): one for Git/bin and another for Git/cmd, which I hadn't been aware of before. Looking in Git/cmd, I noticed that it contained a file git.cmd which appeared to be some kind of script wrapping git.exe. So, I went into the Jenkins configuration and changed the path to the git executable to git.cmd. And that fixed everything!

Based on what I've seen when searching for this error, it seems like there are quite a few potential causes for it. But this is what worked for me in my situation and I haven't seen this solution elsewhere, so I thought I'd write it down... if nothing else to help me remember if it happens again.

8 comments:

RambleCampbell said...

Hey, thanks for the post! Sadly, I'm still having the same problem. Can I ask you a question: what do you mean by "Ensuring that Jenkins was running as the correct user."? I have pageant running as a collaborator on a project, and I can clone using GIT GUI, but Jenkins fails. Do I somehow have to run the Jenkins service as a different user tied to the SSH collaborator key? Any help you could provide would be most appreciated. Thanks, Landon [email protected]

Unknown said...

@RambleCampbell: I just mean ensuring that Jenkins is running as the user you expect it to be running as and that that user has a .ssh directory in place that works for talking to github. Unfortunately, I probably can't help you more than that. I've fought with this issue a couple times and I think there are various things that can cause it, most of which I don't know how to fix off the top of my head. Good luck!

M H J Bramwell said...

I saw this too after getting just a config.xml in an email! It was easy enough to spot ...

<project>
:
<scm class="hudson.plugins.git.GitSCM">
:
<gitTool>Git for GitHub</gitTool>
:
</scm>
:
:
</project>

... versus ...

<project>
:
<scm class="hudson.plugins.git.GitSCM">
:
<gitTool>Default</gitTool>
:
</scm>
:
:
</project>

Cem Tonguç said...

thnx.. I changed the user and it works fine

Rajasekar said...

Hi, I am new to Jenkins and trying out some example from a tutorial,
My build stuck after this
"Cloning the remote Git repository
Cloning repository origin"
And i don't know where i have made mistake, but, i could successfully clone the code from command prompt

Rajasekar said...

Can you please help me with some pointers?

Alec Munro said...

Going into Jenkins config and pointing git to git.cmd worked for me too!
Thanks

meat said...

Thanks very much for the post! In more recent versions of Git, it appears that the Git/cmd directory contains another git.exe and not a git.cmd script. Regardless, changing the Jenkins configuration to point to Git/cmd/git.exe fixed the problem for me.

Post a Comment