詹金斯挂在 git fetch

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36749195/
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-19 11:57:26  来源:igfitidea点击:

Jenkins hangs at git fetch

gitgithubjenkinssshjenkins-plugins

提问by mogoli

I'm a newbie with Jenkins and Im trying to get it to run some unit tests in my.NET project.

我是 Jenkins 的新手,我试图让它在我的 .NET 项目中运行一些单元测试。

When I run a build it hangs when trying to fetch from the git repository.

当我运行构建时,它在尝试从 git 存储库中获取时挂起。

ERROR: Timeout after 10 minutes

错误:10 分钟后超时

C:\Program Files\Git\cmd\git.exe config --local --remove-section credential # timeout=10 ERROR: Error fetching remote repo 'origin' hudson.plugins.git.GitException: Failed to fetch from https://github.com/name.of.repo

C:\Program Files\Git\cmd\git.exe config --local --remove-section credential # timeout=10 错误:获取远程 repo 'origin' hudson.plugins.git.GitException 时出错:无法从https获取: //github.com/name.of.repo

I've generated the known hosts and copied the .ssh dir to C:\Windows\SysWOW64\config\systemprofile.ssh as per the jenkins instructions at https://wiki.jenkins-ci.org/display/JENKINS/Git+Pluginunder "Jenkins, GIT plugin and Windows"

我已经按照https://wiki.jenkins-ci.org/display/JENKINS/Git+ 上的 jenkins 说明生成了已知主机并将 .ssh 目录复制到 C:\Windows\SysWOW64\config\systemprofile.ssh插件下“詹金斯,GIT插件和Windows”

I ran ssh [email protected] from the cmd line and I can succesfully authenticate.

我从 cmd 行运行 ssh [email protected] 并且我可以成功进行身份验证。

Any ideas please?

请问有什么想法吗?

Thanks :)

谢谢 :)

采纳答案by Bert Jan Schrijver

This is probably a firewall issue. You can authenticate to Github using SSH (port 22), so that route is working. Your job however is trying to access github via https://github.com(port 443) which timeouts. Try accessing github over ssh by changing the repository url to [email protected]:account/repository.git(you can find this URL on the main page of the repo, dropdown 'Choose a clone URL', option 'SSH'.

这可能是防火墙问题。您可以使用 SSH(端口 22)向 Github 进行身份验证,以便该路由正常工作。但是,您的工作是尝试通过超时的https://github.com(端口 443)访问 github 。尝试通过 ssh 访问 github,方法是将存储库 url 更改为[email protected]:account/repository.git(您可以在存储库的主页上找到此 URL,下拉“选择克隆 URL”,选项“SSH”。

回答by Daniel

I had the same problem as the OP. SSH credentials are stored in Jenkins and work for many other nodes accessing the same repo. I can ssh into the machine as the Jenkins user and do a git cloneon the repo using the same SSH repo URL as the Jenkins job ([email protected]:account/repo.git).

我遇到了与 OP 相同的问题。SSH 凭证存储在 Jenkins 中,可用于访问同一存储库的许多其他节点。我可以以 Jenkins 用户身份通过​​ ssh 进入机器,并git clone使用与 Jenkins 作业 ( [email protected]:account/repo.git)相同的 SSH 存储库 URL 在存储库上执行操作。

As a workaround, I set the git credentials in the Jenkins job to nonefor now. I assume that allows it to use the credentials stored locally.

作为一种解决方法,我暂时将 Jenkins 作业中的 git 凭据设置none为。我认为这允许它使用本地存储的凭据。

It is working now.

它现在正在工作。

回答by ifeegoo

Before you try to use SSH to access your remote Git repository instead of username & password,you must pay attention to the Timeout Settings for clone and fetch.

在尝试使用 SSH 代替用户名和密码访问远程 Git 存储库之前,您必须注意克隆和获取的超时设置。

When you have a bad internet connection and a large size of remote repository will cause you clone timeout.

当您的 Internet 连接不良且远程存储库大小较大时,将导致克隆超时。

Go to the project settings:Source Code Management-> Additional Behaviours-> Advanced clone behaviours-> Timeout (In Minutes) for clone and fetch operations-> more than 10 minutes.

进入项目设置:Source Code Management-> Additional Behaviours-> Advanced clone behaviours-> Timeout (In Minutes) for clone and fetch operations-> 超过10分钟。

enter image description here

在此处输入图片说明

And then if you are still have the same problem that the git clone stuck for a long time whether a bad internet connection or a large size of remote repository or not,you can try to use SSH to access your remote Git repository instead of username & password.

然后如果你仍然有同样的问题 git clone 卡了很长时间,无论是网络连接不好还是远程存储库很大,你可以尝试使用 SSH 来访问你的远程 Git 存储库,而不是用户名 &密码。

回答by mohitmayank

A simpler alternative to using SSH is to add this snippet before running any gitcommand.

使用 SSH 的一个更简单的替代方法是在运行任何git命令之前添加此代码段。

echo "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.intuit.com" >> /tmp/gitcredfile
git config --global credential.helper "store --file=/tmp/gitcredfile"