Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins git fetch intermittent failure

Tags:

git

jenkins

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

like image 516
Tom Bailey Avatar asked Jun 08 '18 10:06

Tom Bailey


1 Answers

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.

like image 54
Togno Avatar answered Oct 14 '22 03:10

Togno