I am using Hudson with git plugin on Mac OS X. My git repository is on my own server and is accessible with SSH. I have keys configured properly. I am starting Hudson from command line using the default Winstone server. Cloning from command line works and everything worked very well from Hudson before one day I wanted to force Hudson to clear the repository before the build. And so I checked the Clean workspace before build in the Advanced Project Options group. From now on, every single build fails with the following message:
Started by user anonymous
Cleaning the workspace because project is configured to clean the workspace before each build.
Checkout:workspace / /Users/mczenko/.hudson/jobs/My Project/workspace - hudson.remoting.LocalChannel@592e4ff9
Using strategy: Default
Last Built Revision: Revision fc233689562bf464b08d7406a382d4bee0209c04 (origin/master)
Checkout:workspace / /Users/user/.hudson/jobs/My Project/workspace - hudson.remoting.LocalChannel@592e4ff9
Cloning the remote Git repository
Cloning repository origin
ERROR: Error cloning remote repo 'origin' : Could not clone git@myserver.com:git/MyProject.git
ERROR: Cause: Exception caught during execution of fetch command
Trying next repository
ERROR: Could not clone repository
FATAL: Could not clone
hudson.plugins.git.GitException: Could not clone
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:913)
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:845)
at hudson.FilePath.act(FilePath.java:758)
at hudson.FilePath.act(FilePath.java:740)
at hudson.plugins.git.GitSCM.gerRevisionToBuild(GitSCM.java:845)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:622)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1483)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:507)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:424)
at hudson.model.Run.run(Run.java:1366)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:145)
Initially I thought something is wrong with my ssh configuration and that maybe there is something specific to my server installation. But then I checked the same with one of my GitHub repositories and the problems persists. There are many similar questions related to this problem, most of them referring to configuration of ssh - which turns out to be done correctly on my system. I also found the message at http://wiki.hudson-ci.org/display/HUDSON/Git+Plugin suggesting that this failure may be caused by a problem with the path to the git executable. I checked that of course and as expected it makes no difference on my system. Even closer problem is reported here: Hudson git clone error where Rob Segal says:
This is exactly the problem I have been running into. If I do a clone on command line first into the workspace where hudson will be working future builds work fine. Something is clearly going on wrong with the initial cloning process but I can't say what exactly at this point. No doubt debugging the Git plugin code could reveal exactly what is wrong. If I ever get some free time I plan to do this.
I haven't found so far any reference to the situation I have, where the failure in clone seems to be correlated with enabling Clean workspace before build option.
Git plugin has its own option Wipe out workspace before build, which seems to have the same function as the Clean workspace before build option mentioned above. It has the same effect on cloning: after enabling it, cloning fails with the message above.
Once I noticed the problem, the work around seems to be not to use the Clean workspace before build option and not to use git plugin for fresh builds (and doing git clone in the build step), but I am not sure if this is really the problem. Maybe someone has the same problem and can point out some solution.