Jenkins 无法从远程 git 获取代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31129417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:20:51  来源:igfitidea点击:

Jenkins not able to fetch code from remote git

gitjenkins

提问by nishat

My jenkins build is suddenly not working now.The error is as follows:-

我的 jenkins 构建现在突然不工作了。错误如下:-

Fetching changes from the remote Git repository
 > git config remote.origin.url <url> # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from <url>
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:735)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:983)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1016)
    at hudson.scm.SCM.checkout(SCM.java:484)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1270)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:622)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:528)
    at hudson.model.Run.execute(Run.java:1759)
    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:529)
    at hudson.model.ResourceController.execute(ResourceController.java:89)
    at hudson.model.Executor.run(Executor.java:240)
Caused by: hudson.plugins.git.GitException: Command "git config remote.origin.url <url> returned status code 4:
stdout: 
stderr: error: failed to write new configuration file .git/config.lock

I am not able to figure out the root cause. I have checked the permission and ownership for jenkins home folder which is /var/lib/jenkins:- drwxrwxrwx 17 jenkins jenkins 4096 Jun 25 04:30 jenkins

我无法找出根本原因。我已经检查了 jenkins 主文件夹的权限和所有权,它是 /var/lib/jenkins:- drwxrwxrwx 17 jenkins jenkins 4096 Jun 25 04:30 jenkins

Permission and ownership of .git folder inside workspace folder of jenkins is:- drwxrwxrwx 8 jenkins jenkins 4096 Jun 30 21:51 .git

jenkins 的工作区文件夹中 .git 文件夹的权限和所有权是:- drwxrwxrwx 8 jenkins jenkins 4096 Jun 30 21:51 .git

Please guide me fix the problem.

请指导我解决问题。

回答by thepolina

Experienced it when Jenkins VM was running out of disk space. Cleaned it up, don't see this problem anymore.

在 Jenkins VM 磁盘空间不足时体验过它。清理了,再也看不到这个问题了。

回答by JohnnyRico

I was seeing the same issue, but disk space and VM memory were not the problem. What fixed it for me was making the job re-clone on build:

我看到了同样的问题,但磁盘空间和 VM 内存不是问题。对我来说修复它的是在构建时重新克隆工作:

  1. Go to the job's "Configure" page
  2. Under Source Code Management → Git → Additional Behaviors, add a behavior "Wipe out repository & force clone"
  3. Save
  4. Build
  1. 转到作业的“配置”页面
  2. 在 Source Code Management → Git → Additional Behaviors 下,添加一个行为“Wipe out repository & force clone”
  3. 节省
  4. 建造

回答by Johnny5

Try clearing out the workspace files and rebuilding.

尝试清除工作区文件并重建。

回答by cnmuc

In my case, fetching/downloading the remote code was quite slow and was aborted due to a timeout. So I increased the "Timeout (in minutes) for clone and fetch operations" to 20 minutes.

就我而言,获取/下载远程代码非常缓慢,并且由于超时而中止。因此,我将“克隆和获取操作的超时(以分钟为单位)”增加到 20 分钟。

enter image description here

在此处输入图片说明

回答by Vipin Kumar R. Jaiswar

In my case, found that my infrastructure team member changed the ownership of the workspace. After changing folder ownership (in my case it jenkins:apache) its start working.

就我而言,发现我的基础架构团队成员更改了工作区的所有权。更改文件夹所有权(在我的情况下是 jenkins:apache)后,它开始工作。

Thanks & Regards Jaiswar Vipin Kumar R.

感谢和问候 Jaiswar Vipin Kumar R.

回答by Merav2110

we deleted the branches from gitlab, but the slaves weren't updated so we saw this error. We deleted the workspace and it looks ok

我们从 gitlab 中删除了分支,但是从站没有更新,所以我们看到了这个错误。我们删除了工作区,看起来没问题

回答by Rodrigo Justino da Costa

I resolved clean every git directory into /var/lib/jenkins/caches:

我将每个 git 目录清理到 /var/lib/jenkins/caches 中:

 ls
git-18890751adbbb4acf793765536038794      git-4e3aa803edee6bea2129fd817c36f896      git-9f242af77f8053aed6fedce8d0a76e3d      git-e41ee04648298b79b4c7743c24ef70bd  git-fceab3b3b569be214a737dca642e9276
git-18890751adbbb4acf793765536038794@tmp  git-4e3aa803edee6bea2129fd817c36f896@tmp  git-9f242af77f8053aed6fedce8d0a76e3d@tmp  git-e41ee04648298b79b4c7743c24ef70bd@tmp  git-fceab3b3b569be214a737dca642e9276@tmp
git-3733802e4022f95fbc60b4cb18a03217      git-551e81c26de5bcb6a5378e19af1e1be6      git-abf9e4e7e290be76e1f5b71ec660963e      git-e707f9321b2bb37b96406ef713030927
git-3733802e4022f95fbc60b4cb18a03217@tmp  git-551e81c26de5bcb6a5378e19af1e1be6@tmp  git-abf9e4e7e290be76e1f5b71ec660963e@tmp  git-e707f9321b2bb37b96406ef713030927@tmp
git-383d5f162d992a4ab05c37bf92f5a6a6      git-778102e2deb4f6ba3addd2a6598b243c      git-c0a299dd0e54280fdc284e0f84116c25      git-ee5e64ec787f47fcbc3d1fb72b7f3431
git-383d5f162d992a4ab05c37bf92f5a6a6@tmp  git-778102e2deb4f6ba3addd2a6598b243c@tmp  git-c0a299dd0e54280fdc284e0f84116c25@tmp  git-ee5e64ec787f47fcbc3d1fb72b7f3431@tmp
sh-4.2$ rm -rf git*

回答by coltdorsey

I resolved this error by setting the User Account Control settings to "Never notify" and restarting the machine and reconnecting the node to Jenkins.

我通过将用户帐户控制设置设置为“从不通知”并重新启动机器并将节点重新连接到 Jenkins 来解决此错误。