Tom Bailey
Tom Bailey

Reputation: 455

Jenkins git fetch intermittent failure

It seems that some overnight Jenkins jobs are failing intermittently, so they only fail sometimes. Console output below:

Started by timer
Checking out git ssh://[email protected]:2222/repo-here.git into /opt/jenkins/home/workspace/job_name@script to read Jenkinsfile
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository ssh://[email protected]:2222/repo-here.git
 > git init /opt/jenkins/home/workspace/job-name@script # timeout=10
Fetching upstream changes from ssh://[email protected]:2222/repo-here.git
 > git --version # timeout=10
using GIT_SSH to set credentials GitLab SSH Key for  jenkins
 > git fetch --tags --progress ssh://[email protected]:2222/repo-here.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress ssh://[email protected]:2222/repo-here.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2002)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1721)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:72)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:405)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:614)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1146)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1186)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:113)
    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:144)
    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:67)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:298)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
ERROR: Error cloning remote repo 'origin'
ERROR: Maximum checkout retry attempts reached, aborting
Finished: FAILURE

Jenkins version: Jenkins ver. 2.126 Git: 3.9.0
Git client plugin: 2.7.2 OS: CentOS

Upvotes: 7

Views: 22742

Answers (3)

Prashant
Prashant

Reputation: 161

In my case, it was due to the configuration setting for Max # of builds to keep and Max # of builds to keep with artifacts.

I have left those empty but as soon as I have added number to these settings( 5 and 4 here), issue got resolved:

enter image description here

Upvotes: 1

Togno
Togno

Reputation: 51

I found a solution on another thread that solved the exact same issue for me: https://serverfault.com/questions/924058/jenkins-occasionally-fails-to-clone-fetch

If you have several Jenkins jobs that fetch the git repository simultaneously via ssh, then you should increase the value of MaxStartups in /etc/ssh/sshd_config on the git server side.

The default value is 10:30:100 (which means that 30% of new connections will be dropped when 10 are already opened), I set the value 30:30:100 and then I have no more issue.

Upvotes: 5

Ramakrishna Yelduti
Ramakrishna Yelduti

Reputation: 447

There are 2 possible resons to get this kind of issue.

  1. As per the logs, we are getting status code as 128. So cross check the user have access to the repo and branch, which you are cloning.
  2. Make sure you are using correct repo name and branch name. other wise similar kind of will occur.

Upvotes: -1

Related Questions