【问题标题】:Jenkins Git Plugin unable to initialize submodulesJenkins Git 插件无法初始化子模块
【发布时间】:2017-10-02 00:12:05
【问题描述】:

我正在使用 Jenkins 构建一个包含多个 Git 子模块的项目。虽然可以获取主存储库,但子模块初始化失败,即使在新克隆上也是如此:

Started by user anonymous
[EnvInject] - Loading node environment variables.
Building in workspace C:\Builds\Test Build
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Done
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository git@bitbucket.org:ACCOUNT/MAIN_REPOSITORY.git
 > C:\Program Files\Git\mingw64\bin\git.exe init C:\Builds\Test Build # timeout=10
Fetching upstream changes from git@bitbucket.org:ACCOUNT/MAIN_REPOSITORY.git
 > C:\Program Files\Git\mingw64\bin\git.exe --version # timeout=10
using GIT_SSH to set credentials Matt's Bitbucket SSH key
 > C:\Program Files\Git\mingw64\bin\git.exe fetch --tags --progress git@bitbucket.org:ACCOUNT/MAIN_REPOSITORY.git +refs/heads/*:refs/remotes/origin/* # timeout=20
 > C:\Program Files\Git\mingw64\bin\git.exe config remote.origin.url git@bitbucket.org:ACCOUNT/MAIN_REPOSITORY.git # timeout=10
 > C:\Program Files\Git\mingw64\bin\git.exe config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > C:\Program Files\Git\mingw64\bin\git.exe config remote.origin.url git@bitbucket.org:ACCOUNT/MAIN_REPOSITORY.git # timeout=10
Fetching upstream changes from git@bitbucket.org:ACCOUNT/MAIN_REPOSITORY.git
using GIT_SSH to set credentials Matt's Bitbucket SSH key
 > C:\Program Files\Git\mingw64\bin\git.exe fetch --tags --progress git@bitbucket.org:ACCOUNT/MAIN_REPOSITORY.git +refs/heads/*:refs/remotes/origin/* # timeout=20
 > C:\Program Files\Git\mingw64\bin\git.exe rev-parse "origin/master^{commit}" # timeout=10
Checking out Revision COMMIT_HASH (origin/master)
Commit message: "Updated Submodules"
 > C:\Program Files\Git\mingw64\bin\git.exe config core.sparsecheckout # timeout=10
 > C:\Program Files\Git\mingw64\bin\git.exe checkout -f COMMIT_HASH
First time build. Skipping changelog.
 > C:\Program Files\Git\mingw64\bin\git.exe remote # timeout=10
 > C:\Program Files\Git\mingw64\bin\git.exe submodule init # timeout=10
FATAL: Command "C:\Program Files\Git\mingw64\bin\git.exe submodule init" returned status code 128:
stdout: 
stderr: fatal: 'submodule' appears to be a git command, but we were not
able to execute it. Maybe git-submodule is broken?

hudson.plugins.git.GitException: Command "C:\Program Files\Git\mingw64\bin\git.exe submodule init" returned status code 128:
stdout: 
stderr: fatal: 'submodule' appears to be a git command, but we were not
able to execute it. Maybe git-submodule is broken?

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1924)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1892)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1888)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1533)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1545)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.submoduleInit(CliGitAPIImpl.java:945)
    at org.jenkinsci.plugins.gitclient.LegacyCompatibleGitAPIImpl.setupSubmoduleUrls(LegacyCompatibleGitAPIImpl.java:81)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.setupSubmoduleUrls(CliGitAPIImpl.java:71)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.setupSubmoduleUrls(CliGitAPIImpl.java:1417)
    at hudson.plugins.git.extensions.impl.SubmoduleOption.onCheckoutCompleted(SubmoduleOption.java:100)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1188)
    at hudson.scm.SCM.checkout(SCM.java:495)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:560)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:485)
    at hudson.model.Run.execute(Run.java:1735)
    at hudson.matrix.MatrixBuild.run(MatrixBuild.java:313)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:405)
Finished: FAILURE

从 Git Bash 运行“git submodule init”按预期工作。
为了让 Jenkins 行为正确,我可能缺少什么?

配置:

  • Windows 7
  • 詹金斯 2.73.1
  • Git 插件 2.5.0
  • Git 客户端插件 3.5.1
  • Git for Windows 2.14.1.windows.1
  • 主仓库和子模块是同一账户下Bitbucket中的私有Git仓库,已交换ssh密钥。
  • 高级子模块行为选项:
    • “递归更新子模块”
    • “使用来自父存储库默认远程的凭据”

这似乎不同于任何一个:

最新的工具版本似乎修复了已知的子模块错误。 我试过以下没有任何效果:

  1. 使用 Jenkins 存储的 SSH 密钥与 ~/.ssh 本地密钥
  2. 使用基于 HTTPS 的 repo 访问而不是 ssh
  3. 在 .gitmodules 中使用相对路径而不是绝对路径
  4. 使用托管在 GitHub 上的存储库而不是 BitBucket

【问题讨论】:

    标签: git jenkins ssh bitbucket


    【解决方案1】:

    git 插件使用了错误的 git.exe。它已被配置为使用来自以下位置的 git.exe:

    C:\Program Files\Git\Mingw64\bin\git.exe
    

    那个位置的 git.exe 显然找不到子模块命令。

    将 git 插件配置为使用默认位置的 git.exe,它将按预期工作。默认位置是:

    C:\Program Files\Git\bin\git.exe
    

    如果我使用失败的 PATH 设置配置 Windows 命令提示符,它会报告相同的消息,

    fatal: 'submodule' 似乎是一个 git 命令,但我们无法执行它。

    如果我使用有效的 PATH 设置配置 Windows 命令提示符,则 git submodule 命令会按预期运行。

    为什么会这样

    可能是您的 git 命令的位置在 Jenkins 中已(错误地)定义为

    C:\Program Files\Git\Mingw64\bin\git.exe
    

    可能是 PATH 环境变量包含该 mingw64 目录。

    【讨论】:

      【解决方案2】:

      我已经在 Windows 10 和 Linux (Ubuntu 17.04) 中构建了这个项目来测试。在这两种情况下,我都直接在 Jenkins 中指定了 SSH 密钥,并专门从 ~/.ssh 中删除了它

      Windows 10 无法构建,类似于上面的列表。 Linux 可以毫无问题地克隆父模块和子模块存储库。

      鉴于这些结果,我得出结论认为问题是特定于 Windows + GitPlugin。

      【讨论】:

        【解决方案3】:

        你确认你的 git 是正确的吗?

        您尝试了吗 - https://wiki.jenkins.io/display/JENKINS/SSH+Agent+Plugin ?

        【讨论】:

        • Jenkins/Git 正确验证并从 Bitbucket 获取主存储库,因此我确信 URL 和验证是正确的。手动执行“git submodule init”是可行的,所以.gtimodule URLs也是正确的。
        • 所以没有 Jenkins 它可以工作,你确认它是相同的 git 版本和 git 用户吗?
        • 我已经确认 Jenkins 正在调用 Windows git.exe,并且它是唯一安装的 Git 版本。 Jenkins 作为以本地系统登录的服务运行;该系统当前有一个(管理员)帐户。我运行的实验读取用户的本地 .ssh 密钥以进行身份​​验证,确认它使用的是正确的用户。这个问题似乎与 Jenkins/子模块交叉产品无关。
        • 您是否使用子模块标记了高级结帐选项?
        • 是的,如上面的“配置”中所列。
        猜你喜欢
        • 1970-01-01
        • 2013-06-30
        • 2012-04-10
        • 1970-01-01
        • 2013-09-03
        • 1970-01-01
        • 2012-11-08
        • 2013-06-02
        • 1970-01-01
        相关资源
        最近更新 更多