Windows 上 Jenkins 中的 git 插件不使用子模块的凭据

标签 git jenkins git-submodules

我在使用 git 的 Windows 上使用 Jenkins 时遇到问题,我可以使用 ssh 凭据从 BitBucket 获取 git 存储库,但是当它尝试获取位于同一帐户的子模块存储库时,我得到了权限异常。

从 git@bitbucket.org:mycomp/at.git 获取上游更改

C:\CI\Git\bin\git.exe --version using GIT_SSH to set credentials Bitbucket key C:\CI\Git\bin\git.exe fetch --tags --progress git@bitbucket.org:mycomp/at.git +refs/heads/:refs/remotes/origin/ C:\CI\Git\bin\git.exe rev-parse "origin/ci^{commit}" Checking out Revision a079842300ba7fc9e6f4e7182c94af2cfc3af0ba (origin/ci) C:\CI\Git\bin\git.exe config core.sparsecheckout C:\CI\Git\bin\git.exe checkout -f a079842300ba7fc9e6f4e7182c94af2cfc3af0ba C:\CI\Git\bin\git.exe rev-list a079842300ba7fc9e6f4e7182c94af2cfc3af0ba C:\CI\Git\bin\git.exe remote C:\CI\Git\bin\git.exe submodule init C:\CI\Git\bin\git.exe submodule sync C:\CI\Git\bin\git.exe config --get remote.origin.url C:\CI\Git\bin\git.exe submodule update FATAL: Command "C:\CI\Git\bin\git.exe submodule update" returned status code 1: stdout: stderr: Cloning into 'include/portal_air'... 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:mycomp/portal_air.git' into submodule path 'include/portal_air' failed

hudson.plugins.git.GitException: Command "C:\CI\Git\bin\git.exe submodule update" returned status code 1:
stdout: 
stderr: Cloning into 'include/portal_air'...
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:mycomp/portal_air.git' into submodule path 'include/portal_air' failed

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1406)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$400(CliGitAPIImpl.java:87)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$6.execute(CliGitAPIImpl.java:741)
    at hudson.plugins.git.extensions.impl.SubmoduleOption.onCheckoutCompleted(SubmoduleOption.java:77)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:908)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1414)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:671)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:580)
    at hudson.model.Run.execute(Run.java:1684)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:231)

最佳答案

是的,这是我在克隆项目及其子模块时遇到的问题。

我使用 https 而不是 git@ 来克隆 repos,git scm 插件只将通过 jenkins 传递的凭据应用到主模块而不是子模块。 为了解决这个问题,我必须运行一个存储凭证并将其传递给任何需要身份验证的 git 操作的进程。像这样 http://www.scmtechblog.net/2014/12/git-authentication-for-automation-script.html

现在,您正在尝试通过 git@ 进行访问,但权限仍然被拒绝,请您确保该帐户对您添加了 ssh key 的子模块存储库具有正确的访问权限。

关于Windows 上 Jenkins 中的 git 插件不使用子模块的凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24929699/

相关文章:

Jenkins 管道: How to get the list of file from workspace?

git - 授予对 github 上单个文件的访问权限

git - 你能用 git 从 future 的提交中 check out 一个文件吗?

jenkins - TFS 2015 中的队列 Jenkins 作业步骤无法与 Jenkins 作业同步

Git rm all that says "deleted by us"在 merge 期间

git - 从 Gitlab webhook 触发 Jenkins 管道

linux - 在多个 Git 存储库之间共享 .mailmap 或其他顶级文件,跨平台

git submodule foreach - 首先递归提交子模块的可靠方法?

git - 有效的全局 .gitignore 步骤不会在 Mac OS 上生效

linux - 我可以从提取中恢复 GIT 存储吗