【问题标题】:Jenkins hangs on Mac slave when cloning from Gitlab instance从 Gitlab 实例克隆时,Jenkins 在 Mac slave 上挂起
【发布时间】:2014-07-11 03:01:01
【问题描述】:

我们正在尝试通过 Jenkins 作业构建 iOS 应用程序,但我们无法从 Gitlab 实例克隆存储库。截至目前,当 git 获取引用时,Jenkins 会挂起(直到 10 分钟超时)。

以下是 Jenkins 输出:

Started by user <USER>
[EnvInject] - Loading node environment variables.
Building remotely on Mac_Slave in workspace /Users/<MAC USER>/Documents/Jenkins/workspace/<REPO>
 > git rev-parse --is-inside-work-tree
Fetching changes from the remote Git repository
 > git config remote.origin.url git@<GITLAB>:<USERNAME>/<REPO>.git
Fetching upstream changes from git@<GITLAB>:<USERNAME>/<REPO>.git
 > git --version
using GIT_SSH to set credentials <MAC SLAVE>
 > git fetch --tags --progress git@<GITLAB>:<USERNAME>/<REPO>.git +refs/heads/*:refs/remotes/origin/*
ERROR: Timeout after 10 minutes
FATAL: Failed to fetch from git@<GITLAB>:<USERNAME>/<REPO>.git
hudson.plugins.git.GitException: Failed to fetch from git@<GITLAB>:<USERNAME>/<REPO>.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:623)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:855)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:880)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1251)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:605)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:514)
    at hudson.model.Run.execute(Run.java:1703)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:231)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress git@<GITLAB>:<USERNAME>/<REPO>.git +refs/heads/*:refs/remotes/origin/*" returned status code 143:
stdout: 
stderr: 
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1307)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1169)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:87)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:257)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:153)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:146)
    at hudson.remoting.UserRequest.perform(UserRequest.java:118)
    at hudson.remoting.UserRequest.perform(UserRequest.java:48)
    at hudson.remoting.Request$2.run(Request.java:328)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at hudson.remoting.Engine$1$1.run(Engine.java:63)
    at java.lang.Thread.run(Thread.java:745)

我们已经添加了 Mac 的 SSH 公钥作为存储库的部署密钥,并且我们使用了 Mac 的 SSH 私钥作为凭据,但由于某种原因,它不起作用。有什么想法吗?

编辑:查看 Mac slave 上的日志,我注意到它提示用户“输入密钥 '/var/folders/92/&lt;RANDOM STRING OF CHARACTERS&gt;/T/ssh&lt;RANDOM STRING OF NUMBERS&gt;key':" 的密码,如果我手动输入 SSH 密钥的密码,它可以工作。但是这个解决方案不是”不适合自动构建系统。

进一步挖掘,如果我真的去'/var/folders/92/&lt;RANDOM STRING&gt;/T/' 文件夹,我会看到一些文件。当 Mac 从机被提示输入密码时,会出现 ssh&lt;RANDOM NUMBERS&gt;key 文件、ssh&lt;DIFF RANDOM NUMBERS&gt;.sh 文件和 pass&lt;OTHER DIFF RANDOM NUMBERS&gt;.sh 文件。 ssh&lt;...&gt;key 文件包含 SSH 私钥,ssh&lt;...&gt;.sh 文件包含使用该私钥的 ssh 命令,pass&lt;...&gt;.sh 文件包含回显 SSH 密码的命令。

【问题讨论】:

  • 如果您使用 Jenkins 使用的相同凭据从命令行运行相同的 git fetch 命令会发生什么?
  • 它工作得很好。使用 Mac 从站手动克隆存储库没有问题。

标签: macos git ssh jenkins gitlab


【解决方案1】:

原来我需要将 SSH 密钥添加到 Mac 的钥匙串或删除 SSH 密钥中的密码。为了添加到钥匙串,在 Mac 上运行 ssh-add &lt;SSH PRIVATE KEY FILE&gt;(您可能还需要启用 ssh-agent 执行 eval $(ssh-agent))。

【讨论】:

    【解决方案2】:

    我的猜测是,您的 Jenkins 从属进程与您从命令行运行 git 的用户不同。如果是这种情况 - 您需要先批准该用户的初始主机密钥验证,然后才能在 Jenkins 中运行 git。 (你知道 - 第一次连接 ssh 时收到的消息:

    The authenticity of host '111.11.11.11' can't be established.
    RSA key fingerprint is 3f:1b:f4:bd:c5:aa:c1:1f:bf:4e:2e:cf:53:fa:d8:59.
    Are you sure you want to continue connecting (yes/no)? 
    

    )

    【讨论】:

    • 有什么方法可以查看 Jenkins 正在使用哪个用户?因为在 Mac 的 .ssh/known_hosts 文件中是对 Gitlab 存储库的引用。
    • echo $USER 在 jenkins 工作中,或者如果您正在使用 envinject 插件(推荐!),您在构建页面上有“环境变量”链接。
    • 用户正确。我刚刚用我发现的更多内容编辑了原始帖子。
    猜你喜欢
    • 2017-01-09
    • 2016-11-18
    • 1970-01-01
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 2012-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多