【问题标题】:Why is Jenkins failing when fetching from git, while the command line isn't?为什么 Jenkins 从 git 获取时失败,而命令行却没有?
【发布时间】:2014-09-08 22:21:09
【问题描述】:

我所有的 Jenkins 构建都在 git fetch 行失败。

git fetch --tags --progress git@bitbucket.org:ethenwilson/whentoact.git 失败

Started by user anonymous
Building in workspace /Users/ethen/.jenkins/workspace/Build NikNik
 > git rev-parse --is-inside-work-tree
Fetching changes from the remote Git repository
 > git config remote.origin.url git@bitbucket.org:ethenwilson/whentoact.git
Fetching upstream changes from git@bitbucket.org:ethenwilson/whentoact.git
 > git --version
using GIT_SSH to set credentials NikNik BitBucket SSH Key
 > git fetch --tags --progress git@bitbucket.org:ethenwilson/whentoact.git +refs/heads/*:refs/remotes/origin/*
FATAL: Failed to fetch from git@bitbucket.org:ethenwilson/whentoact.git
hudson.plugins.git.GitException: Failed to fetch from git@bitbucket.org:ethenwilson/whentoact.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:622)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:854)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:879)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1252)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:624)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:530)
    at hudson.model.Run.execute(Run.java:1732)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:234)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress git@bitbucket.org:ethenwilson/whentoact.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: remote: Counting objects: 2682, done.[K
remote: Compressing objects:   0% (1/1399)   [K
remote: Compressing objects:   1% (14/1399)   [K
...
remote: Compressing objects:  99% (1398/1399)   [K
remote: Compressing objects: 100% (1399/1399)   [K
remote: Compressing objects: 100% (1399/1399), done.[K
Receiving objects:   0% (1/2682)   
Receiving objects:   1% (27/2682)   
...  
Receiving objects:  78% (2092/2682), 4.07 MiB | 1.59 MiB/s   
Corrupted MAC on input.
Disconnecting: Packet corrupt
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1325)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1186)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:87)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:257)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:620)
    ... 10 more

当我从命令行运行 git fetch --tags --progress git@bitbucket.org:ethenwilson/whentoact.git 时,它工作正常,这意味着我的 SSH 密钥必须工作。

我正在使用 Jenkins 通过 SSH 验证连接到 BitBucket。 Jenkins 从它所在的文件(默认文件)中获取密钥,所以我知道 Jenkins 使用的密钥与我从命令行运行时使用的密钥相同。

我正在为 Jenkins 使用最新版本的 BitBucket 和 Git 插件。我在 Mac 上安装的 Git 版本是 1.8.5.2 (Apple Git-48)

我的詹金斯启动命令是nohup java -jar ~/jenkins.war --httpPort=8081 --ajp13Port=8010 > /tmp/jenkins.log 2>&1 &

怎么了?

编辑:我错了,当我这样做时,我不小心点击了一个选项,让 SSH 密钥位于错误的位置。现在,使用@borrrden 的建议,它仍然给出同样的错误。 **编辑:正如@borrrden 所建议的,我将启动命令更改为nohup java -Dorg.jenkinsci.plugins.gitclient.Git.useCLI=true -jar ~/Downloads/jenkins.war --httpPort=8081 --ajp13Port=8010 > /tmp/jenkins.log 2>&1 &,现在我遇到了不同的崩溃:

Started by user anonymous
Building in workspace /Users/ethen/.jenkins/workspace/Build NikNik
 > git rev-parse --is-inside-work-tree
Fetching changes from the remote Git repository
 > git config remote.origin.url git@bitbucket.org:ethenwilson/whentoact.git
Fetching upstream changes from git@bitbucket.org:ethenwilson/whentoact.git
 > git --version
using GIT_SSH to set credentials NikNik BitBucket SSH Key
 > git fetch --tags --progress git@bitbucket.org:ethenwilson/whentoact.git +refs/heads/*:refs/remotes/origin/*
FATAL: Failed to fetch from git@bitbucket.org:ethenwilson/whentoact.git
hudson.plugins.git.GitException: Failed to fetch from git@bitbucket.org:ethenwilson/whentoact.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:622)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:854)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:879)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1252)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:624)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:530)
    at hudson.model.Run.execute(Run.java:1732)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:234)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress git@bitbucket.org:ethenwilson/whentoact.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Permission denied (publickey).
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:1406)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1194)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:87)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:265)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:620)
    ... 10 more

【问题讨论】:

  • 我在 Docker 上的 Jenkins 实例上遇到了同样的问题。当我尝试从终端中的同一工作区使用相同的 SSH 密钥克隆 repo 时,它运行良好,但运行 Jenkins 作业时出现错误Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress git@gitlab.domain.com:SomeName/repo-name.git +refs/heads/*:refs/remotes/origin/*" returned status code 128: 以下所有建议都不起作用:(

标签: git jenkins ssh bitbucket git-fetch


【解决方案1】:

我也遇到了这个问题,只能通过删除工作区在我们的 Jenkins 主服务器上有问题的存储库来解决。

我认为问题在于在一些构建中存在连接错误(如@gbjbaanb 所说)(我们的 Bitbucket 崩溃了)。这使得 master 上的工作空间处于损坏状态,并且由于 Jenkins 尝试尽可能使用缓存的工作空间,这也导致后续构建失败。

【讨论】:

    【解决方案2】:

    1) 进入作业配置

    2) 转到“源代码管理”部分

    3) 附加行为 > 添加

    4) 选择“清除存储库并强制克隆”

    这将只删除并重新克隆适合您工作的工作区。如果您想在删除之前确认,那么我建议通过批处理/bash 命令构建步骤回显 $WORKSPACE 变量。

    此外,这会使构建速度变慢,因此我建议在构建后将其删除。

    【讨论】:

    • 是的!根据 git 插件的版本,该选项也可能称为“轻量级结帐” - 您要禁用它,然后重新运行,然后重新启用。
    【解决方案3】:

    对我来说,这是 git-client 插件的 10 分钟默认超时。

    通过在作业上设置高级克隆行为并增加超时来解决。

    在Git插件部分下的作业配置页面,有一个下拉列表“添加”。在该下拉列表中有一个选择“高级克隆行为”。添加高级克隆行为时,您会看到“克隆和提取操作超时(以分钟为单位)”字段。

    如果您在操作之前添加其他行为,您可以延长克隆和签出的超时时间 - 这已在我的控制台中转换为更高的超时值

    • 高级结帐行为
    • 高级克隆行为

    将任何值放入 timeout 都会覆盖默认值。

    JENKINS-20445获得的知识。

    【讨论】:

      【解决方案4】:

      好像是网络错误:

      接收对象:78% (2092/2682),4.07 MiB | 1.59 MB/秒

      输入的 MAC 损坏。

      断开连接:数据包损坏

      致命:远端意外挂断

      致命:早期 EOF

      致命:索引包失败

      建议网络在 78% 的时候中断。

      好像是commonproblem.

      【讨论】:

      • 那我该怎么做才能修复它?我已经连续测试了大约 50 次这种情况,每个版本都有这种情况,所以这不是一次性的。
      • @EthenA.Wilson 查看编辑,并搜索“git fatal: early EOF”以获取一些修复它的建议方法。
      • 如果是这样,那为什么他可以从命令行克隆没有问题?
      • @borrrden 你得问问他——有时用户说“它总是对我有用”,而他们的意思是“我试过一次”。也许它只是侥幸。也许他的网络是基于用户的QoS。我不知道 - 我知道“远程挂断”是什么意思。
      • @borrrden 在试图找出这个问题的过程中,我尝试使用命令行执行git fetch 大约十几次,并且每次都有效。
      【解决方案5】:

      此问题可能是由于在提取时进行了超时检查。您可以按照下面提到的建议来增加它。

      在Git插件部分下的作业配置页面,有一个下拉列表“添加”。在该下拉列表中有一个选择“高级克隆行为”。添加高级克隆行为时,您会看到“克隆和提取操作超时(以分钟为单位)”字段。

      【讨论】:

        【解决方案6】:

        我在我的 Windows 服务器中遇到了类似的超时问题,我的远程 GIT 存储库很大并且克隆速度非常慢。

        根据post 的建议,我已完成以下操作来解决超时问题。

        1. 手动克隆存储库(不一定是git clone --mirror git@github.com:my-user/my-repository.git,因为在我偶然发现第二个建议之前,我已经将它克隆到了一个文件夹中。无论如何,如果你是新开始的,可能你可以使用mirror 选项进行克隆) .这将作为我的参考存储库。

        2. 在你的jenkins作业中配置Source Code Management如下

        存储库:像往常一样配置它

        要构建的分支:像往常一样配置它

        存储库浏览器:(自动)(默认值)

        其他行为:高级克隆行为

        获取标签 - 未选中

        初始克隆的荣誉参考规范 - 未选中

        浅克隆 - 已检查

        浅克隆深度 - 1(我们不关心整个历史,只有最新就足够了)

        在克隆期间使用的参考存储库的路径 - 克隆整个存储库的存储库的文件夹路径(请参阅上面的步骤 1

        克隆和获取操作的超时(以分钟为单位) - 在我的情况下留空(如果您需要不同的超时(默认为 10 分钟),您可以在此处提及)

        【讨论】:

          【解决方案7】:

          我能够通过专门为 Jenkins 创建一个 BitBucket 帐户来解决这个问题,并授予它对存储库的管理员权限。

          然后我将存储库 URL 设为:https://JenkinsAccountUsername:JenkinsAccountPassword@bitbucket.org/OwnerOfRepositoryUsername/ProjectName.git

          【讨论】:

            【解决方案8】:

            我通过在连接到 BitBucket 时将“ssh”切换为“https”解决了类似的问题。请记住,在 bitbucket UI 上,单击“克隆”时,会出现 ssh/https 的下拉选项。使用 https 后,git pull 工作。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2019-02-02
              • 2010-11-03
              • 2015-09-01
              • 2020-05-14
              • 2013-01-28
              • 1970-01-01
              • 2010-10-26
              相关资源
              最近更新 更多