git - Jenkins git 子模块更新失败

标签 git jenkins bitbucket git-submodules

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

控制台输出如下:

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.access$500(CliGitAPIImpl.java:62)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$7.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

最佳答案

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

  1. 将顶级存储库添加到源代码管理 -> Git
  2. 选择“其他行为”添加按钮
    • 选择“高级子模块行为”
  3. 我只测试了“递归更新子模块”并得到了“权限被拒绝”错误(见底部*)
  4. 但是,我现在在 Jenkins 2.41 中同时选择了“递归更新子模块”和“使用父存储库的默认远程凭据”

一旦我选择了这两个选项,它就会使用我为顶级存储库配置的凭据,一切都对我有用。这是带有 Git 插件 3.0.1 的 2.41 中的对话框: git submodule authentication configuration under Jenkins 2.41

* 这是我的“权限被拒绝”错误的实质:

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

关于git - Jenkins git 子模块更新失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35312274/

相关文章:

git - 如何识别 Jenkins 管道中的 merge 提交?

windows - 如何在 Jenkins-ci 中归档参数化构建的工件

bitbucket - 我可以从 bitbucket 管道中的其他管道执行管道吗?

bitbucket - 通过松弛响应 bitbucket 评论时如何将回复格式化为代码片段?

jenkins - 使用 Jenkins 管道将工件存档/发布到 Samba 共享

git - 在 Windows 服务器上从 bitbucket 自动部署到 iis

git - 是否可以选择 Dependabot 应该针对其打开 PR 的特定分支?

git - 将克隆的 git 添加到个人 Gitlab

git - 如何将 Git 存储库中可用的包添加到 Buildroot?

jenkins - "java.lang.IllegalArgumentException: Expected a closure or failFast"运行并行构建时出现异常