Jenkins git fetch 不定期失败

5

看起来一些 Jenkins 的夜间作业会间歇性地失败,因此它们只有时而失败。以下是控制台输出:

Started by timer
Checking out git ssh://git@gitlab.domain.com: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://git@gitlab.domain.com:2222/repo-here.git
 > git init /opt/jenkins/home/workspace/job-name@script # timeout=10
Fetching upstream changes from ssh://git@gitlab.domain.com:2222/repo-here.git
 > git --version # timeout=10
using GIT_SSH to set credentials GitLab SSH Key for  jenkins
 > git fetch --tags --progress ssh://git@gitlab.domain.com: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://git@gitlab.domain.com: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版本:Jenkins ver. 2.126
Git版本:3.9.0
Git客户端插件:2.7.2
操作系统:CentOS


在运行Docker中的Jenkins时,Ubuntu 16.04上出现了相同的问题。我不确定是否有解决方案。 - markovchain
2个回答

5
我在另一个线程上找到了一个解决方案,成功地解决了我的相同问题: https://serverfault.com/questions/924058/jenkins-occasionally-fails-to-clone-fetch 如果您有多个Jenkins作业通过ssh同时获取git存储库,则应该增加git服务器端的/etc/ssh/sshd_config中的MaxStartups值。
默认值为10:30:100(这意味着当已打开10个连接时,将有30%的新连接被丢弃),我将值设置为30:30:100,然后就没有问题了。

/git服务器上的/etc/ssh/sshd_config是吗?如果是这样,调整git服务器的中央设置并不总是适用于所有人,而且它可能会对其他未使用Jenkins的项目产生影响...而且这种解决方案在可扩展性方面也不是很好,比如说将来你想要在100个以上的节点上并行运行作业... - YaP

-1

出现这种问题可能有两个原因。

  1. 根据日志,我们得到状态码为128。请确认用户是否有访问您正在克隆的仓库和分支的权限。
  2. 确保您使用的是正确的仓库名称和分支名称。否则会出现类似的问题。

2
这是一个间歇性问题,因此细节必须正确。 - Tom Bailey
请回答以下问题。您是使用GitHub还是VSTS-GIT?如果是VSTS-GIT,请问是否使用了备用凭据? - Ramakrishna Yelduti
Git插件以及使用Gitlab作为代码仓库。 - Tom Bailey

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接