【发布时间】:2018-02-21 00:02:51
【问题描述】:
如何在 .gitlab-ci.yml 中为 gitlab-ci 中的子模块(不同的 repo)指定分支?
【问题讨论】:
标签: continuous-integration gitlab continuous-deployment gitlab-ci
如何在 .gitlab-ci.yml 中为 gitlab-ci 中的子模块(不同的 repo)指定分支?
【问题讨论】:
标签: continuous-integration gitlab continuous-deployment gitlab-ci
连同@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_script 与GIT_SUBMODULE_STRATEGY 提供的功能相同(除了我可以将--remote 标志添加到before_script):https://docs.gitlab.com/ee/ci/yaml/README.html#git-submodule-strategy
【讨论】:
你没有。您在您正在构建的项目的.gitmodules 文件中指定它。
[submodule "MyRepo"]
path = MyRepo
url = https://github.com/vendor/MyRepo.git
branch = master
【讨论】:
.gitsubmodules 文件中有这个,但是当我推送到 gitlab 时,会使用任何分支的最新提交
.gitmodules