3

My goal is to pull a Private Github Repository to Jenkins.

Here are some backgrounds:

  1. MacOS
  2. Jenkins hosted locally, localhost:8080
  3. Installed Git plugin and Github plugin in Jenkins.
  4. If I turn the repository to Public, everything is good in Jenkins.
  5. From commandline, I can do "git clone" that private repo with the same credentials I used in Jenkins.

But when I turn it to Private and use it as the Source for Jenkins, it's broken.

The errors are:

Building in workspace /Users/Shared/Jenkins/Home/jobs/TestFramework/workspace
     > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
    Fetching changes from the remote Git repository
     > /usr/bin/git config remote.origin.url https://github.com/XXXXXXX/testframework.git # timeout=10
    Fetching upstream changes from https://github.com/XXXXXXX/testframework.git
     > /usr/bin/git --version # timeout=10
    using GIT_ASKPASS to set credentials 
     > /usr/bin/git fetch --tags --progress https://github.com/XXXXXXX/testframework.git +refs/heads/*:refs/remotes/origin/* # timeout=5
    ERROR: Timeout after 5 minutes
    ERROR: Error fetching remote repo 'origin'
    hudson.plugins.git.GitException: Failed to fetch from https://github.com/XXXXXXX/testframework.git
        at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:806)
        at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1070)
        at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1101)
        at hudson.scm.SCM.checkout(SCM.java:496)
        at hudson.model.AbstractProject.checkout(AbstractProject.java:1278)
        at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:604)
        at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
        at hudson.model.Run.execute(Run.java:1728)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:98)
        at hudson.model.Executor.run(Executor.java:405)
    Caused by: hudson.plugins.git.GitException: Command "/usr/bin/git fetch --tags --progress https://github.com/XXXXXXX/testframework.git +refs/heads/*:refs/remotes/origin/*" returned status code 143:

I tried a few suggestions online:

  1. ssh-keygen to /Users/shared/jenkins/.ssh/id_rsa
  2. ssh-keygen to /Users/jason/.ssh/id_rsa
  3. Add both corresponding "id_rsa.pub" to private repository "Settings" => "Deploy keys".

But still not working.

y.luis.rojo
  • 1,794
  • 4
  • 22
  • 41
翁鹏飞
  • 421
  • 1
  • 5
  • 6
  • The command I used to create SSH is just: ssh-keygen . Should I add some tags? Not sure about it. thanks – 翁鹏飞 Apr 04 '17 at 12:01
  • I would mark this question as a duplicate, but I don't see that option. Maybe my reputation is too low. Anyway, I think you should look at this post. https://stackoverflow.com/questions/5212304/authenticate-jenkins-ci-for-github-private-repository – user985366 Jul 31 '17 at 14:23
  • This question is not a duplicate of the link you posted @user985366. The issue here is a fetch tag timeout of a private repo using git repo. The question link you commented is related to authentication and setup – Ashwin G Aug 17 '17 at 19:53

1 Answers1

2

I guess the problem might be that: When Jenkins tries to clone a repo or get information about a repo, it will use a username called jenkins. Of course, this user doesn't have access to your private repo. If you do it from command line, you will be using your own username, thus you can clone a repo successfully.

You can solve this by changing the setting of your source code management in the configuration of your project.

What we are doing is to use a "Username with password" credential for github repo.

  1. After you input "Repository URL", you could click the "Add" button near "Credential" to add a "Username with password" credential.
  2. In the pop-up window, choose the "Username with password" for the "Kind" field.
  3. Type in your username and password of your Github account and save it.
  4. Then you can choose this credential you just added in the "Credential" field when setting up the source code management.

Hope this could help you.

(Adding your account and password with credential plugin is somehow safe so you don't need to worry about exposing your account and password)

Chong
  • 335
  • 2
  • 9
  • I face the issue, and I already have my repo configured with the credential plugin, still same error – Ashwin G Aug 17 '17 at 19:54