【问题标题】:How to specify the submodule branch in gitlab-ci?如何在 gitlab-ci 中指定子模块分支?
【发布时间】:2018-02-21 00:02:51
【问题描述】:

如何在 .gitlab-ci.yml 中为 gitlab-ci 中的子模块(不同的 repo)指定分支?

【问题讨论】:

    标签: continuous-integration gitlab continuous-deployment gitlab-ci


    【解决方案1】:

    连同@stefan 对这个问题的回答。您还必须告诉 Git 只查看最新提交的指定分支。 git submodule update 似乎总是获取最新的提交,无论分支如何。执行 git submodule update --remote 似乎会强制 git 专注于您在 .gitmodules 文件中指定的分支。

    所以在你的.gitmodules 文件中,正如@stefen 提到的那样:

    [submodule "MyRepo"]
        path = MyRepo
        url = https://github.com/vendor/MyRepo.git
        branch = master
    

    然后在你的 GitLab .gitlab-ci.yml 文件中,你需要指定在设置子模块时只查看配置的分支。我的文件包括这个before_script

    # GitLab CI provides a variable "GIT_SUBMODULE_STRATEGY" that sets up submodules automatically
    # But then branch tracking doesn't work (doesn't seem to allow for specifying the --remote) flag
    before_script:
     - git submodule sync --recursive
     - git submodule update --init --remote --recursive
    

    根据文档,这个before_scriptGIT_SUBMODULE_STRATEGY 提供的功能相同(除了我可以将--remote 标志添加到before_script):https://docs.gitlab.com/ee/ci/yaml/README.html#git-submodule-strategy

    【讨论】:

      【解决方案2】:

      你没有。您在您正在构建的项目的.gitmodules 文件中指定它。

      [submodule "MyRepo"]
          path = MyRepo
          url = https://github.com/vendor/MyRepo.git
          branch = master
      

      【讨论】:

      • 这对我不起作用。我在我的.gitsubmodules 文件中有这个,但是当我推送到 gitlab 时,会使用任何分支的最新提交
      • @ZachSmith 该文件应称为.gitmodules
      • 是的....确实应该(并且是)。那是问题中的错字。道歉。我在下面添加了一个答案
      猜你喜欢
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 2022-01-10
      • 1970-01-01
      • 2018-08-30
      相关资源
      最近更新 更多