繁体   English   中英

为什么从 git 获取时 Jenkins 失败,而命令行不是?

[英]Why is Jenkins failing when fetching from git, while the command line isn't?

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

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

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

我的 jenkins 启动命令是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

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

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

在此输入图像描述 1)转到作业配置

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

3)其他行为>添加

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

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

此外,这使得构建速度慢得多,所以我建议在构建之后删除它。

看起来像网络错误:

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

输入时MAC损坏。

断开连接:数据包损坏

致命:远程端意外挂断

致命:早期EOF

致命:索引包失败

表明该网络在78%的时间内突破了。

似乎是一个常见 问题。

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

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

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

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

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

在超时中放置任何值都会覆盖默认值。

JENKINS-20445获得的知识。

此问题可能是由提取时的超时检查引起的。 您可以按照下面提到的建议增加它。

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

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

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

我在连接到BitBucket时将'ssh'切换为'https'解决了类似的问题。 记住在bitbucket UI上,当点击'clone'时,有ssh / https的下拉选项。 使用https后,git pull工作。

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

我已根据此帖的建议完成以下操作来修复超时问题。

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

  2. 在jenkins作业中配置Source Code Management ,如下所示

存储库像平常一样配置它

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

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

其他行为 :高级克隆行为

获取标签 - 未选中

尊重refspec初始克隆 - 未选中

浅克隆 - 检查

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

克隆期间使用的引用repo的路径 - 克隆整个repo的repo的文件夹路径(请参阅上面的步骤1

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

我正在尝试连接到 bitbucket 存储库。在向 Jenkins 凭证存储添加新凭证后,我遇到了这个问题。删除并重新创建用户名和密码凭证以连接到存储库对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM