Jenkins git 子模块更新失败

Jenkins git submodule update fails

我有一个 git 存储库,其中有一个子模块。两者都属于 BitBucket 上的一个团队。我的 jenkins 机器是带有 git 插件的 AWS windows 服务器。我正在使用 SSH 密钥进行身份验证。 我有三个詹金斯工作。一个克隆主仓库。这是成功的。一个自己克隆第二个 repo(将用作子模块的 repo)。这也是成功的。 在我的第三次构建工作中,我告诉 jenkins 递归更新子模块。这会失败并显示 public-key 错误。如果我可以自己克隆 repo,怎么会这样呢?

以下控制台输出:

Started by user anonymous
Building on master in workspace C:\Program Files (x86)\Jenkins\jobs\MainRepo\workspace
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository git@bitbucket.org:team/mainrepo.git
 > git.exe init C:\Program Files (x86)\Jenkins\jobs\mainrepo\workspace # timeout=10
Fetching upstream changes from git@bitbucket.org:team/mainrepo.git
 > git.exe --version # timeout=10
using GIT_SSH to set credentials 
 > git.exe -c core.askpass=true fetch --tags --progress git@bitbucket.org:team/mainrepo.git +refs/heads/*:refs/remotes/origin/*
 > git.exe config remote.origin.url git@bitbucket.org:team/mainrepo.git # timeout=10
 > git.exe config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git.exe config remote.origin.url git@bitbucket.org:team/mainrepo.git # timeout=10
Fetching upstream changes from git@bitbucket.org:team/mainrepo.git
using GIT_SSH to set credentials 
 > git.exe -c core.askpass=true fetch --tags --progress git@bitbucket.org:team/mainrepo.git +refs/heads/*:refs/remotes/origin/*
 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision 6b3f6535c45e79ee88f4918d464edead48d83369 (refs/remotes/origin/master)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f 6b3f6535c45e79ee88f4918d464edead48d83369
 > git.exe rev-list 6b3f6535c45e79ee88f4918d464edead48d83369 # timeout=10
 > git.exe remote # timeout=10
 > git.exe submodule init # timeout=10
 > git.exe submodule sync # timeout=10
 > git.exe config --get remote.origin.url # timeout=10
 > git.exe submodule update --init --recursive
FATAL: Command "git.exe submodule update --init --recursive" returned status code 128:
stdout: 
stderr: Cloning into 'my-submodule'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@bitbucket.org:team/my-submodule.git' into submodule path 'my-submodule' failed

hudson.plugins.git.GitException: Command "git.exe submodule update --init --recursive" returned status code 128:
stdout: 
stderr: Cloning into 'my-submodule'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@bitbucket.org:team/my-submodule.git' into submodule path 'my-submodule' failed

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1693)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access0(CliGitAPIImpl.java:62)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.execute(CliGitAPIImpl.java:953)
    at hudson.plugins.git.extensions.impl.SubmoduleOption.onCheckoutCompleted(SubmoduleOption.java:90)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1098)
    at hudson.scm.SCM.checkout(SCM.java:485)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
    at hudson.model.Run.execute(Run.java:1738)
    at hudson.matrix.MatrixBuild.run(MatrixBuild.java:301)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:410)
Finished: FAILURE

作为替代方案,您可以使用 'Source Code Management' - 'Multiple SCMs' 手动配置所有子模块并为每个子模块添加 'Additional Behaviours' - 'Check out to a sub-directory'。

他们似乎已经用版本 git 客户端插件 1.20.0-beta1git 插件 2.5 修复了它.0-beta1。但是,它们只能通过指定从实验更新中心拉取更新来添加到 Jenkins。

根据此处较早的回答,我 re-prioritized 升级了我客户的 Jenkins。现在他们在带有 Git 插件 3.0.1 的 Jenkins 2.41 上,在进行额外配置之前,这并没有解决问题。我发现配置有点棘手:

  1. 将 top-level 存储库添加到源代码管理 -> Git
  2. Select "Additional Behaviours" 添加按钮
    • Select "Advanced sub-modules behaviours"
  3. 我仅使用 "Recursively update submodules" 进行测试并得到 "Permission denied" 错误(见底部*)
  4. 但是,我现在 select 在 Jenkins 2.41
  5. 中 "Recursively update submodules" 和 "Use credentials from default remote of parent repository"

一旦我 select 这两个选项,它就会使用我为 top-level 存储库配置的凭据,一切都对我有用。这是带有 Git 插件 3.0.1 的 2.41 中的对话框:

* 这是我的 "Permission denied" 错误的实质:

Cloning into 'thirdparty'...

stderr: Permission denied (publickey). fatal: The remote end hung up unexpectedly Clone of 'ssh://hg@bitbucket.org//thirdparty' into submodule path 'thirdparty' failed

PS 在 posting 之前,我像往常一样仔细检查以确保我没有重复回答。在这种情况下,我看到@danielfn 的评论指向的内容与我的回答几乎相同,但是 1. 这对我没有帮助,我最终通过反复试验弄清楚了,并且 2. Whosebug 的政策是 post 在这里回答而不是引用外部链接。