10

I'm a beginner with Jenkins and I'm trying to get it to run some unit tests in my.NET project.

When I run a build it hangs when trying to fetch from the Git repository.

ERROR: Timeout after 10 minutes
 > C:\Program Files\Git\cmd\git.exe config --local --remove-section credential # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://github.com/name.of.repo

I've generated the known hosts and copied the .ssh dir to C:\Windows\SysWOW64\config\systemprofile.ssh as per the jenkins instructions at https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin under "Jenkins, GIT plugin and Windows"

I ran ssh git@github.com from the command line and I can successfully authenticate.

What can I try next?

halfer
  • 19,824
  • 17
  • 99
  • 186
mogoli
  • 2,153
  • 6
  • 26
  • 41

4 Answers4

11

This is probably a firewall issue. You can authenticate to Github using SSH (port 22), so that route is working. Your job however is trying to access github via https://github.com (port 443) which timeouts. Try accessing github over ssh by changing the repository url to git@github.com:account/repository.git (you can find this URL on the main page of the repo, dropdown 'Choose a clone URL', option 'SSH'.

Bert Jan Schrijver
  • 1,521
  • 10
  • 16
  • This worked for me. Many thanks, much appreciated :) – mogoli Apr 21 '16 at 09:21
  • 4
    how about if it is intermittent? Got any ideas? The majority of clone operations work fine but some hang forever – Peter Kahn Apr 27 '17 at 02:16
  • Does the problem appear for all builds/jobs or for specific ones? If it happens incidentally, I suspect it's a netwerk/firewall related issue. When a clone operation hangs, are you able to reach github.com from the Jenkins node? And how about other web sites? – Bert Jan Schrijver Apr 29 '17 at 09:51
2

I had the same problem as the OP. SSH credentials are stored in Jenkins and work for many other nodes accessing the same repo. I can ssh into the machine as the Jenkins user and do a git clone on the repo using the same SSH repo URL as the Jenkins job (git@git.com:account/repo.git).

As a workaround, I set the git credentials in the Jenkins job to none for now. I assume that allows it to use the credentials stored locally.

It is working now.

Daniel
  • 3,243
  • 2
  • 32
  • 31
0

Before you try to use SSH to access your remote Git repository instead of username & password,you must pay attention to the Timeout Settings for clone and fetch.

When you have a bad internet connection and a large size of remote repository will cause you clone timeout.

Go to the project settings:Source Code Management -> Additional Behaviours -> Advanced clone behaviours -> Timeout (In Minutes) for clone and fetch operations -> more than 10 minutes.

enter image description here

And then if you are still have the same problem that the git clone stuck for a long time whether a bad internet connection or a large size of remote repository or not,you can try to use SSH to access your remote Git repository instead of username & password.

ifeegoo
  • 7,054
  • 3
  • 33
  • 38
0

A simpler alternative to using SSH is to add this snippet before running any git command.

echo "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.intuit.com" >> /tmp/gitcredfile
git config --global credential.helper "store --file=/tmp/gitcredfile"
mohitmayank
  • 631
  • 2
  • 7
  • 20