Jenkins can not clone Git repository over Git/SSH on Windows
Solution 1
I've gone through these pains recently. Especially frustrating is the lack of error logs in this scenario: probably because MSysgit prompts user on the console when trying to recover - which doesn't get through Jenkins console.
Based on my experience here are a few key elements to watch for:
- a mix of both Msysgit and Cygwin installed: MSysgit worked better for me- but I assume you're using that too
- some people have more luck with
<MSYSGIT_ROOT>\cmd\git.cmd
than<MSYSGIT_ROOT>\bin\git.exe
- making sure your slave runs as the same user (which is not the default upon service-based installs).. - oh I see you got that too
- setting
HOME
variable for windows slaves explicity - basically make sure the same .ssh keys are reached when under Jenkins.
- for debugging, I found it useful to create a test job with no SCM, but run
git clone
in an "Execute shell/batch" build step. That should reveal a bit more info. BTW, you can do anenv
in the same step and maybels %HOME%/.ssh
I think the above is what gave me a working a Windows 7 64bit Jenkins slave with git support - although I thought this had more to do with some other fine config detail than with 64 vs 32 bits. Good luck anyhow!
Solution 2
In the latest version of git, had to use %GIT_HOME%/cmd/git.exe, rather than %GIT_HOME%/bin/git.exe and figuring out the home directory of the user running the jenkins service.
Solution 3
Another issue i faced with was, ssh.exe was not looking at the %userprofile%/.ssh
folder for the key files. Instead it was looking to the folder C:\Program Files (x86)\Git\.ssh
which was empty and which causes a hang due to ssh authentication prompt on the machine where git repo located.
We just copied the key files under %userprofile%/.ssh
to C:\Program Files (x86)\Git\.ssh
and the problem is resolved.
Solution 4
Notes from a hard learned lesson. I had problems getting the ssh to work running Jenkins as a named user account for ssh+git.
Here is what I had to do to solve the problem:
- Generate the key using ssh-keygen (note where they are located)
- Set "HOME" to this location
I tried with puttygen and GET_SSH=plink that all failed very bad but no clear errors.
Željko Filipin
Freelance software engineer. International contractor at the Wikimedia Foundation.
Updated on July 09, 2022Comments
-
Željko Filipin almost 2 years
I have successfully cloned Git repository in Jenkins over Git/SSH on Windows 2008 32-bit. When I tried to do the same on Windows 2008 64-bit, Console Output page gets stuck here:
Démarré par l'utilisateur anonymous Checkout:book / C:\Jenkins\workspace\book - hudson.remoting.LocalChannel@1da691a Using strategy: Default Last Built Revision: Revision 5d7ce4ae23c91fb201ee005e6db17bcd795ca965 (origin/HEAD, origin/master) Checkout:book / C:\Jenkins\workspace\book - hudson.remoting.LocalChannel@1da691a Cloning the remote Git repository Cloning repository origin
When I stop the build (after a few minutes of being stuck there), I get the rest of the error message:
ERROR: Error cloning remote repo 'origin' : Could not clone [email protected]:zeljkofilipin/watirbook.git ERROR: Cause: Error performing command: C:\Git\bin\git.exe clone --progress -o origin [email protected]:zeljkofilipin/watirbook.git C:\Jenkins\workspace\book 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:1042) at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:968) at hudson.FilePath.act(FilePath.java:785) at hudson.FilePath.act(FilePath.java:767) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:968) at hudson.model.AbstractProject.checkout(AbstractProject.java:1193) at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:567) at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:455) at hudson.model.Run.run(Run.java:1404) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:230)
- I can clone the repository via Git read-only URL
git://github.com/zeljkofilipin/watirbook.git
from Jenkins on both machines - I can clone via Git/SSH URL
[email protected]:zeljkofilipin/watirbook.git
from the command line on both machines - I can clone via Git/SSH URL from Jenkins on 32-bit machine, but not on 64-bit machine.
The only difference I can notice between the two machines (not counting that one is a virtual machine on my laptop, and another is a real machine in Switzerland) is that the first one is 32-bit and the second one is 64-bit.
Not sure if that could be related, but 32-bit machine has location set to Croatia, and 64-bit machine to Switzerland (as you can see from Git output in French).
For more information please see my blog post: Jenkins, Windows and Git
- I can clone the repository via Git read-only URL