【问题标题】:How to track down a Jenkins failure to checkout git submodule over ssh?如何追踪 Jenkins 未能通过 ssh 签出 git 子模块?
【发布时间】:2015-04-24 17:31:40
【问题描述】:

我正在使用 bitbucket 和 Jenkins 进行构建。我的项目有一个子模块,需要在构建过程中签出。我正在使用的顶级 git 存储库运行良好。它使用具有 SSH 访问权限的部署密钥将其从 bitbucket 中提取出来。我在两个存储库上都有相同的部署密钥。我还让我的子模块相对于我的项目定义:

[submodule "platform/web-app/WEB-INF/learning"]
    path = platform/web-app/WEB-INF/learning
    url = ./../xxxxxxxx.git

但是,当 Jenkins 构建项目时,它会拉下顶级存储库并在子模块期间失败。 Jenkins 正在使用 EC2 插件构建它,因此它构建在按需启动的从属盒上。我试图在盒子上手动执行 git,但它以同样的方式失败。我不完全理解 ssh 密钥是如何被推到盒子上的,但我不明白如何调试它。为什么这对一个模块有效,但对子模块无效?

这是输出:

FATAL: Command "git submodule update --init --recursive" returned status code 1:
stdout: Cloning into 'platform/web-app/WEB-INF/learning'...

stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.
Clone of 'git@bitbucket.org:xxxxxxxx/xxxxxxx.git' into submodule path 'platform/web-app/WEB-INF/learning' failed

hudson.plugins.git.GitException: Command "git submodule update --init --recursive" returned status code 1:

stdout: Cloning into 'platform/web-app/WEB-INF/learning'...

stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.
Clone of 'git@bitbucket.org:xxxxxxxx/xxxxxx.git' into submodule path 'platform/web-app/WEB-INF/learning' failed

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1148)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1125)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1121)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:937)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.submoduleUpdate(CliGitAPIImpl.java:598)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.submoduleUpdate(CliGitAPIImpl.java:579)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:299)
    at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:280)
    at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:239)
    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 java.lang.Thread.run(Thread.java:744)

【问题讨论】:

  • 会不会是因为stackoverflow.com/a/18912392/6309?还是stackoverflow.com/questions/19550590/…? (即用于 Jankins 的专用帐户没有具有正确私有/公共 ssh 密钥的 ~/.ssh/
  • 此外,此线程可以帮助突出 Jenkins 连接到 Bitbucket 存储库所需的步骤:answers.atlassian.com/questions/85436/…
  • 可能是这样,但这是一台 ec2 机器,它会启动以执行构建,因此每次都会删除盒子的状态。如果它没有〜/ .ssh,但它没有,它怎么能毫无问题地检查初始回购然后在子模块上失败?如果没有.ssh,现在如何工作?
  • 那么这就是你的问题。也许最初的 repo 不使用 ssh url,而是使用 https 的,允许公共匿名(未经身份验证)访问。而子模块在父仓库的.gitmodules 中注册了一个ssh url。
  • 我已经确认配置设置为使用 ssh。从日志中:使用 GIT_SSH 设置凭据 Jenkins Bitbucket 访问密钥。它说了两次,这让我觉得它使用相同的密钥来访问子模块 repo。

标签: git amazon-ec2 jenkins bitbucket jenkins-plugins


【解决方案1】:

我认为您遇到了此处报告的问题:https://issues.jenkins-ci.org/browse/JENKINS-20941

从我看到的症状来看,您放入 Jenkins 的凭据用于检查顶级存储库,但在尝试获取子模块更新时并未使用它们。

解决方法有两个角度:

  • 将密钥文件放到所有构建从属服务器上
  • 更新您的作业配置以显式更新

或者您可以等待维护人员修复它,或者自己修复它:-)

希望对你有帮助

【讨论】:

  • 我通过使用 MultiSCM 插件分别检查每个模块来解决这个问题。我很高兴知道这实际上是一个错误,我并没有发疯。
  • 第二个角度的“显式更新”是什么意思?我尝试了构建步骤,以及插件的一些子模块选项,但没有一个工作。谢谢。
  • 通过“显式更新”,我的意思是按照 wierzbiks 下面的建议 - 添加一个构建步骤来运行 Jenkins 自身无法正确执行的命令。诚然,我选择将密钥文件放到所有从属服务器上,所以我不能准确地说出需要哪些命令。对不起。
【解决方案2】:

我在作业配置中使用具有特定凭据的 ssh-agent。然后在构建步骤中,我有“Exec shell”组件:

git submodule init
git submodule sync
git submodule update --init --recursive

【讨论】:

    猜你喜欢
    • 2018-12-01
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 2015-06-29
    • 2021-12-06
    • 2017-10-21
    相关资源
    最近更新 更多