Im building GIT project on slave. When a job workspace dir is empty (either I clean it manually via workspace wipe out button or use Git plugin configuration option "Wipe out workspace before build")the build crashes on checkout. After that, on the filesystem I have only one folder .git. It contains standard git folders (but empty) and two files HEAD and config. HEAD contains

ref: refs/heads/master

However, if I run the build again on that folder, the files will be checked out successfully. The problem occures only when the workspace is empty. HEAD content after successfull checkout

b9f5b15f0760d26543ba208d536a2f0c75b94237

Log after 1st attempt (empty workspace - build failed)

Started by user <MyUser>
Building remotely on punt
Checkout:test_git / /hudson/workspace/test_git - hudson.remoting.Channel@3e8eae1e:punt
Using strategy: Default
Last Built Revision: Revision b9f5b15f0760d26543ba208d536a2f0c75b94237 (origin/master)
Checkout:test_git / /hudson/workspace/test_git - hudson.remoting.LocalChannel@1a254ec
Cloning the remote Git repository
Cloning repository origin
ERROR: Error cloning remote repo 'origin' : Could not clone <MyGitRepo>
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:957)
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:889)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2052)
at hudson.remoting.UserRequest.perform(UserRequest.java:107)
at hudson.remoting.UserRequest.perform(UserRequest.java:41)
at hudson.remoting.Request$2.run(Request.java:276)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)

We had this issue a lot. We use Git with SSH. I've seen this with Github projects as well as internal Gerrit projects. As a result we do not clean the workspace but use "Clean after checkout" until this is fixed.

Great! Thank to the full stack trace we can identify the problem, btw why it is not always enabled? It looks like there is a problem with authorization on the first attemp. I keep repo credentials in .netrc file. So what is the problem?

Clean checkout

Started by user zapalak
Building remotely on punt
Checkout:test-git / /hudson2/workspace/test-git - hudson.remoting.Channel@37dd0b4c:punt
Using strategy: Default
Last Built Revision: Revision 27964cc90aad85d37cc6379c89cc4eb6467ceb1e (origin/master)
Checkout:test-git / /hudson2/workspace/test-git - hudson.remoting.LocalChannel@32b6481e
Cloning the remote Git repository
Cloning repository origin
ERROR: Error cloning remote repo 'origin' : Could not clone https://<MyGitRepo>/SeeingAssistant/SeeingAssistant-Routes
hudson.plugins.git.GitException: Could not clone https://<MyGitRepo>/SeeingAssistant/SeeingAssistant-Routes
at hudson.plugins.git.GitAPI.clone(GitAPI.java:234)
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:942)
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:889)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2052)
at hudson.remoting.UserRequest.perform(UserRequest.java:107)
at hudson.remoting.UserRequest.perform(UserRequest.java:41)
at hudson.remoting.Request$2.run(Request.java:276)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
Caused by: org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of fetch command
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:145)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:174)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:118)
at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:224)
at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:218)
at hudson.FilePath.act(FilePath.java:791)
at hudson.FilePath.act(FilePath.java:773)
at hudson.plugins.git.GitAPI.clone(GitAPI.java:218)
... 12 more
Caused by: org.eclipse.jgit.errors.TransportException: https://<MyGitRepo>/SeeingAssistant/SeeingAssistant-Routes: not authorized
at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:446)
at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:276)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:127)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:113)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1062)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:136)
... 19 more
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:958)
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:889)
at hudson.FilePath$FileCallableWrapper.call(FilePath.java:2052)
at hudson.remoting.UserRequest.perform(UserRequest.java:107)
at hudson.remoting.UserRequest.perform(UserRequest.java:41)
at hudson.remoting.Request$2.run(Request.java:276)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)

The problem is obviously connected with authorization process. First checkout is successful when I clone from public repository. I tried both .netrc and credential.helper (osxkeychain in my case - MACOS) to store credentials and they works fine from command line but not from Hudson.

Do we have any permanent fix for this ? Or do I need to do the modification in the known_hosts file?

Thanks in advance for the help!!

Error I am getting is :

Cloning the remote Git repository
Cloning repository origin
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not clone git@server:test.git
at hudson.plugins.git.GitAPI.clone(GitAPI.java:255)
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:1063)
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:1008)
at hudson.FilePath.act(FilePath.java:793)
at hudson.FilePath.act(FilePath.java:775)
at hudson.plugins.git.GitSCM.gerRevisionToBuild(GitSCM.java:1008)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:777)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1550)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:607)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:518)
at hudson.model.Run.run(Run.java:1493)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:82)
at hudson.model.Executor.run(Executor.java:137)
Caused by: hudson.plugins.git.GitException: org.eclipse.jgit.api.errors.TransportException: git@server:test.git: UnknownHostKey: server. RSA key fingerprint is 62:ad:32:1a:da:52:4c:41:a4:d8:c0:a8:0b:80:c3:d3
at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:248)
at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:235)
at hudson.FilePath.act(FilePath.java:793)
at hudson.FilePath.act(FilePath.java:775)
at hudson.plugins.git.GitAPI.clone(GitAPI.java:235)
... 13 more
Caused by: org.eclipse.jgit.api.errors.TransportException: git@server:test.git: UnknownHostKey: server. RSA key fingerprint is 62:ad:32:1a:da:52:4c:41:a4:d8:c0:a8:0b:80:c3:d3
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:139)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:178)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:125)
at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:242)
... 17 more
Caused by: org.eclipse.jgit.errors.TransportException: git@server:test.git: UnknownHostKey: server. RSA key fingerprint is 62:ad:32:1a:da:52:4c:41:a4:d8:c0:a8:0b:80:c3:d3
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:142)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:121)
at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:248)
at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:147)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1111)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:130)
... 20 more
Caused by: com.jcraft.jsch.JSchException: UnknownHostKey: server. RSA key fingerprint is 62:ad:32:1a:da:52:4c:41:a4:d8:c0:a8:0b:80:c3:d3
at com.jcraft.jsch.Session.checkHost(Session.java:786)
at com.jcraft.jsch.Session.connect(Session.java:342)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:116)
... 27 more
Trying next repository
FATAL: Could not clone repository
hudson.plugins.git.GitException: Could not clone repository
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:1074)
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:1008)
at hudson.FilePath.act(FilePath.java:793)
at hudson.FilePath.act(FilePath.java:775)
at hudson.plugins.git.GitSCM.gerRevisionToBuild(GitSCM.java:1008)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:777)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1550)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:607)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:518)
at hudson.model.Run.run(Run.java:1493)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:82)
at hudson.model.Executor.run(Executor.java:137)