为什么Jenkins在从git获取时失败,而命令行不是';T

为什么Jenkins在从git获取时失败,而命令行不是';T,git,jenkins,ssh,bitbucket,git-fetch,Git,Jenkins,Ssh,Bitbucket,Git Fetch,我所有的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 chang

我所有的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密钥必须正常工作

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

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

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

怎么了

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


似乎是网络错误:

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

输入时损坏的MAC

断开连接:数据包损坏

致命:远程端意外挂起

致命:早期EOF

致命:索引包失败

表明网络在78%的时间里崩溃了


似乎是一个

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


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

对我来说,这是git客户端插件的10分钟默认超时

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

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

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

  • 高级签出行为
  • 高级克隆行为
将任何值放入超时将覆盖默认值


从中获得的知识。

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


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

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

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

1) 转到作业配置

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

3) 其他行为>添加

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

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


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

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

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

根据本文的建议,我已经做了以下工作来修复超时问题

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

  • 在jenkins作业中配置
    源代码管理
    ,如下所示

  • 存储库:按正常方式进行配置

    要构建的分支:按正常方式配置此分支

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

    其他行为:高级克隆行为

    获取标记-未选中

    在初始克隆时遵守refspec-未选中

    浅克隆-已检查

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

    克隆期间要使用的参考回购的路径-克隆整个回购的回购的文件夹路径(参见上文步骤1)

    克隆和获取操作的超时(分钟)-在my中留空
    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