Jenkins间歇性git连接错误

时间:2016-11-04 12:14:19

标签: git jenkins jenkins-plugins gitlab

我有一个Jenkins工作,99%的时间没有问题,但偶尔我会在尝试获取时收到Git插件生成的错误。有问题的Git仓库托管在GitLab。

此错误的来源可能是Jenkins,网络连接或GitLab。

我的问题是,是否有人在GitLab或其他地方使用Jenkins和Git托管过类似的问题?

堆栈跟踪(出于安全原因而编辑):

Building remotely on [MACHINE_NAME] (build) in workspace c:\workspace\location
 > C:\location\of\git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > C:\location\of\git\bin\git.exe config remote.origin.url git@git.<gitlab-server>:My/project.git # timeout=10
Fetching upstream changes from git@git.<gitlab-server>:My/project.git
 > C:\location\of\git\bin\git.exe --version # timeout=10
using GIT_SSH to set credentials 
 > C:\location\of\git\bin\git.exe fetch --tags --progress git@git.<gitlab-server>:My/project.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git@git.<gitlab-server>:My/project.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:797)
    ...
    at hudson.model.Executor.run(Executor.java:404)
Caused by: hudson.plugins.git.GitException: Command "C:\location\of\git\bin\git.exe fetch --tags --progress git@git.<gitlab-server>:My/project.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:1752)
    ...
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:795)
    ... 11 more
ERROR: null
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Finished: FAILURE

编辑(基于投票)
到目前为止进行的研究(我定期运行詹金斯的工作):

  1. 修改Jenkins以从Jenkins运行的机器上的特定文件中读取ssh私钥 - 间歇性地观察到错误
  2. 将ssh私钥直接复制并粘贴到Jenkins中(如果是文件 访问权限问题1.) - 间歇性地观察到错误
  3. Git命令作为Jenkins运行的Windows机器上的预定作业运行(试图消除Jenkins作为问题的根源) - 等待结果......
  4. 如果第3点产生错误,那么我可以确定它是GitLab或网络连接问题。如果没有,那么我可以肯定它是詹金斯的问题。如果有人注意到这个问题,我会感激他们知道他们是如何解决的。

    更新(根据研究结果)

    上面第3点提到的工作是在周末每小时运行一次。没有观察到错误。詹金斯的工作也在周末每小时运行,并且观察到两个错误。 这支持了Jenkins Git插件问题的理论。

3 个答案:

答案 0 :(得分:1)

在Jenkins服务器上运行ProcessExplorer,然后查找孤立的 Git进程。例如,使用SourceTree:

enter image description here

解决方案:

可能会有一些Git.exe进程正在运行,请杀死它们,杀死进程树。一次一次,重要的是尝试缩小范围并分享您的发现:)

要测试是否可行,请在Jenkins中重新输入git repo路径(这将导致刷新),然后您将看不到尝试连接到Git的错误。

您可能可以使用任务管理器代替ProcessExplorer,我发现使用ProcessExplorer以及通常使用SysInternal工具可以更好地进行诊断。

答案 1 :(得分:1)

在我的情况下,问题是由于sshd中的“ MaxStartups”指令引起的,该指令指定了到SSH守护程序的并发未认证连接的最大数量(有关详细信息,请参见man sshd_config)。

当许多Jenkins作业同时运行时,这可能导致与SSH守护程序的许多并发未经身份验证的连接,在这种情况下sshd将开始删除连接。您可以在/ etc / ssh / sshd_config中设置“ MaxStartups”指令,以增加sshds将开始删除连接的并发未经身份验证的连接数(默认为10)。

与此相关的问题:https://serverfault.com/questions/924058/jenkins-occasionally-fails-to-clone-fetch

答案 2 :(得分:0)

就我而言,公司有人编辑了 /etc/ssh/ssh_config 文件并添加了自定义 ProxyCommand。我注释掉了那行,它奏效了。