我有一个git repo,它有一个子模块。两者都属于BitBucket的团队。我的jenkins机器是带有git插件的AWS windows服务器。我使用SSH密钥进行身份验证。 我有三个詹金斯工作。一个克隆主要回购。这很成功。一个人自己克隆第二个回购(将用作子模块的回购)。这也很成功。 在我的第三个构建工作中,我告诉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
答案 0 :(得分:23)
根据此前的答案,我重新确定了升级客户端Jenkins的优先顺序。现在他们使用Git插件3.0.1在Jenkins 2.41上,在进行额外配置之前,这并没有解决问题。我发现配置有点棘手:
一旦我选择了这两个选项,它就会使用我为顶级存储库配置的凭据,一切都适合我。以下是2.41中使用Git插件3.0.1的对话框:
*这是我的“权限被拒绝”错误的本质:
克隆成'第三方'......
stderr:权限被拒绝(publickey)。致命的:远程端挂了 意外地克隆了 'ssh://hg@bitbucket.org//thirdparty'进入子模块路径 'thirdparty'失败
PS在发布之前,我做了我平常的双重检查以确保我没有重复答案。在这种情况下,我看到@ danielfn的评论指向与我的答案几乎完全相同的东西,但是1.这对我没有帮助,我最终通过反复试验找出它并且2.它是StackOverflow政策发布的这里回答而不是引用外部链接。
答案 1 :(得分:5)
作为替代方案,您可以使用“源代码管理” - “多个SCM”手动配置所有子模块,并为每个子模块添加“附加行为” - “签出到子目录”。
答案 2 :(得分:5)
似乎他们已经使用 git客户端插件1.20.0-beta1 和 git插件2.5.0-beta1 版本修复了它。但是,只能通过指定从实验更新中心提取更新来将它们添加到Jenkins中。
答案 3 :(得分:1)
这个是是jenkins中的一个已知错误:https://issues.jenkins-ci.org/browse/JENKINS-20941但它现在已经修复,更新你的Git插件来解决问题。
如果无法进行更新,可以将密钥放在jenkins-users .ssh文件夹中作为解决方法。