git Jenkins 无法从 Gitlab 克隆,因为超时

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

Jenkins fail to clone from Gitlab because timeout

gitsshjenkins

提问by V-SHY

I faced error when I try to build my Gitlab project in Jenkins.

当我尝试在 Jenkins 中构建我的 Gitlab 项目时遇到错误。

What I tried

我试过的

  1. Set the system environment as Setup your environment variables for Git Plugin Jenkins
  2. Under “git” change “Path to Git executable” to GIT_FOLDER\cmd\git.cmd (NOT GIT_FOLDER\bin\git.exe)
  3. Using PsExec.exe to let the “Local System account” accessed by Jenkins server to have SSH keys or known_hosts set up and verify via

    "GIT_FOLDER\bin\ssh.exe" -T [email protected]

  4. Even success to fetch via the same command in the

    "C:\Program Files (x86)\Git\bin\sh.exe" -login -i window

  5. Fill in the Gitlab host url and API Token for Jenkins account in Gitlab server

  6. Create credential with ssh key with no passphrase and selected in project credential
  1. 将系统环境设置Setup your environment variables for Git Plugin Jenkins
  2. 在“git”下,将“路径到 Git 可执行文件”更改为 GIT_FOLDER\cmd\git.cmd(不是 GIT_FOLDER\bin\git.exe)
  3. 使用 PsExec.exe 让 Jenkins 服务器访问的“本地系统帐户”设置 SSH 密钥或 known_hosts 并通过以下方式验证

    "GIT_FOLDER\bin\ssh.exe" -T [email protected]

  4. 即使通过相同的命令获取成功

    "C:\Program Files (x86)\Git\bin\sh.exe" -login -i 窗口

  5. 在Gitlab服务器中填写Jenkins账号的Gitlab主机url和API Token

  6. 使用没有密码短语的 ssh 密钥创建凭据并在项目凭据中选择

Jenkins Build Error Log

Jenkins 构建错误日志

(git_repository.git represents my git repository url)

(git_repository.git 代表我的 git 仓库 url)

Started by user Jenkins

由用户 Jenkins 发起

Building in workspace C:\Program Files (x86)\Jenkins\jobs\MyApp-Test\workspace

在工作区 C:\Program Files (x86)\Jenkins\jobs\MyApp-Test\workspace 中构建

C:\Program Files (x86)\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10

C:\Program Files (x86)\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10

Fetching changes from the remote Git repository

从远程 Git 存储库获取更改

C:\Program Files (x86)\Git\bin\git.exe config remote.origin.url git_repository.git # timeout=10

C:\Program Files (x86)\Git\bin\git.exe config remote.origin.url git_repository.git # timeout=10

Fetching upstream changes from git_repository.git

从 git_repository.git 获取上游更改

C:\Program Files (x86)\Git\bin\git.exe --version # timeout=10

C:\Program Files (x86)\Git\bin\git.exe --version # timeout=10

using GIT_SSH to set credentials

使用 GIT_SSH 设置凭据

C:\Program Files (x86)\Git\bin\git.exe -c core.askpass=true fetch --tags --progress git_repository.git +refs/heads/:refs/remotes/origin/

C:\Program Files (x86)\Git\bin\git.exe -c core.askpass=true fetch --tags --progress git_repository.git +refs/heads/ :refs/remotes/origin/

ERROR: Timeout after 10 minutes
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git_repository.git
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:485)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1282)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:610)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:532)
at hudson.model.Run.execute(Run.java:1741)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:381)
Caused by: hudson.plugins.git.GitException: Command "C:\Program Files (x86)\Git\bin\git.exe -c core.askpass=true fetch --tags --progress git_repository.git +refs/heads/*:refs/remotes/origin/*" returned status code -1:
stdout: 
stderr: 
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1591)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1379)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access0(CliGitAPIImpl.java:86)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.execute(CliGitAPIImpl.java:324)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:733)
... 11 more
ERROR: Error fetching remote repo 'origin'

回答by V-SHY

Change the credential of the free style project to default option - none -

将自由风格项目的凭据更改为默认选项- 无 -

Because the ssh will use the API tokenof the Gitlabplugin value to access to the Gitlab server.

由于SSH将使用令牌API中的Gitlab插件价值访问Gitlab服务器。

Therefore if you specify another SSH key to access the Gitlab server in the project, they will stuck forever.

因此,如果您在项目中指定另一个 SSH 密钥来访问 Gitlab 服务器,它们将永远卡住。

This took my one week to find this out.

这花了我一周的时间才发现这一点。

回答by Unity

I got the same error when I mistakenly created a .git folder in the remote application folder. Deleting the folder fixed it.

当我错误地在远程应用程序文件夹中创建了一个 .git 文件夹时,我遇到了同样的错误。删除文件夹修复了它。