Jenkins git 子模块更新失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35312274/
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
Jenkins git submodule update fails
提问by SlimCheney
I have a git repo which has one submodule. Both belong to a team on BitBucket. My jenkins machine is a AWS windows server with the git plugin. I am using SSH keys for authentication. I have three jenkins jobs. One clones the main repo. This is successful. One clones the second repo on its own (the repo which will be used as a submodule). This is also successful. In my third build job I tell jenkins to recursively update the submodules. This fails and says public-key error. How can this be the case if I can clone the repo on its own?
我有一个 git repo,它有一个子模块。两者都属于 BitBucket 上的一个团队。我的 jenkins 机器是带有 git 插件的 AWS Windows 服务器。我正在使用 SSH 密钥进行身份验证。我有三个詹金斯工作。一个克隆主仓库。这是成功的。一个人自己克隆第二个 repo(将用作子模块的 repo)。这也是成功的。在我的第三个构建工作中,我告诉 jenkins 递归更新子模块。这失败并说公钥错误。如果我可以自己克隆 repo,怎么会是这种情况?
Console output below:
控制台输出如下:
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 [email protected]:team/mainrepo.git
> git.exe init C:\Program Files (x86)\Jenkins\jobs\mainrepo\workspace # timeout=10
Fetching upstream changes from [email protected]:team/mainrepo.git
> git.exe --version # timeout=10
using GIT_SSH to set credentials
> git.exe -c core.askpass=true fetch --tags --progress [email protected]:team/mainrepo.git +refs/heads/*:refs/remotes/origin/*
> git.exe config remote.origin.url [email protected]: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 [email protected]:team/mainrepo.git # timeout=10
Fetching upstream changes from [email protected]:team/mainrepo.git
using GIT_SSH to set credentials
> git.exe -c core.askpass=true fetch --tags --progress [email protected]: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 '[email protected]: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 '[email protected]: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
采纳答案by 1615903
This iswas a known bug in jenkins: https://issues.jenkins-ci.org/browse/JENKINS-20941but it has now been fixed, update your Git plugin to resolve the issue.
这是jenkins 中的一个已知错误:https://issues.jenkins-ci.org/browse/JENKINS-20941但现已修复,请更新您的 Git 插件以解决该问题。
If updating is not possible, as a workaround, you could put the key in jenkins-users .ssh folder.
如果无法更新,作为一种解决方法,您可以将密钥放在 jenkins-users .ssh 文件夹中。
回答by sage
Based on the earlier answers here, I re-prioritized upgrading my client's Jenkins. Now they are on Jenkins 2.41 with Git plugin 3.0.1 and before additional configuration this did not fix the issue. I found the configuration to be a little tricky:
根据此处较早的答案,我重新确定了升级客户的 Jenkins 的优先级。现在他们在 Jenkins 2.41 上使用 Git 插件 3.0.1 并且在额外配置之前这并没有解决问题。我发现配置有点棘手:
- Add top-level repository to Source Code Management -> Git
- Select the "Additional Behaviours" Add button
- Select "Advanced sub-modules behaviours"
- I tested with only "Recursively update submodules" and got the "Permission denied" error (see bottom*)
- However, I now select both "Recursively update submodules" and "Use credentials from default remote of parent repository" in Jenkins 2.41
- 将顶级存储库添加到源代码管理 -> Git
- 选择“其他行为”添加按钮
- 选择“高级子模块行为”
- 我只用“递归更新子模块”进行了测试并得到“权限被拒绝”错误(见底部*)
- 但是,我现在在 Jenkins 2.41 中同时选择“递归更新子模块”和“使用父存储库默认远程的凭据”
Once I select both options, it uses the credentials I had configured for the top-level repository and everything works for me. Here is what the dialog looks like in 2.41 with Git plugin 3.0.1:
一旦我选择了这两个选项,它就会使用我为顶级存储库配置的凭据,一切都对我有用。以下是 2.41 中带有 Git 插件 3.0.1 的对话框的样子:
* Here is the essence of my "Permission denied" error:
*这是我的“权限被拒绝”错误的本质:
Cloning into 'thirdparty'...
stderr: Permission denied (publickey). fatal: The remote end hung up unexpectedly Clone of 'ssh://[email protected]//thirdparty' into submodule path 'thirdparty' failed
克隆到“第三方”...
stderr:权限被拒绝(公钥)。致命:远程端意外挂断 'ssh://[email protected]//thirdparty' 克隆到子模块路径 'thirdparty' 失败
PS Just before posting, I did my usual double check to make sure I'm not duplicating an answer. In this case, I see that @danielfn's comment points to something that is nearly identical to my answer, but 1. this didn't help me and I ended up figuring it out by trial and error and 2. it is StackOverflow policy to post answers here rather than referencing external links.
PS 就在发布之前,我做了我通常的双重检查以确保我没有重复答案。在这种情况下,我看到@danielfn 的评论指向的内容与我的答案几乎相同,但是 1. 这对我没有帮助,我最终通过反复试验弄明白了 2. 发布是 StackOverflow 政策在这里回答而不是引用外部链接。
回答by Qi Luo
As an alternative, you may use 'Source Code Management' - 'Multiple SCMs' to manually configure all the sub-modules and add 'Additional Behaviours' - 'Check out to a sub-directory' for each one.
作为替代方法,您可以使用“源代码管理”-“多个 SCM”手动配置所有子模块并为每个子模块添加“附加行为”-“签出到子目录”。
回答by danielfn
It seems that they have fixed it with the versions git client plugin 1.20.0-beta1and git plugin 2.5.0-beta1. However, they can only be added to Jenkins by specifying to pull updates from the experimental update center.
似乎他们已经使用git client plugin 1.20.0-beta1和git plugin 2.5.0-beta1版本修复了它。但是,它们只能通过指定从实验更新中心拉取更新来添加到 Jenkins。