如何在 gitlab-ci 中 specify 子模块分支?
How to specify the submodule branch in gitlab-ci?
如何在 .gitlab-ci.yml 中为 gitlab-ci 中的子模块(不同的 repo)进行 specify 分支?
你不知道。您在正在构建的项目的 .gitmodules
文件中指定它。
[submodule "MyRepo"]
path = MyRepo
url = https://github.com/vendor/MyRepo.git
branch = master
连同@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
如何在 .gitlab-ci.yml 中为 gitlab-ci 中的子模块(不同的 repo)进行 specify 分支?
你不知道。您在正在构建的项目的 .gitmodules
文件中指定它。
[submodule "MyRepo"]
path = MyRepo
url = https://github.com/vendor/MyRepo.git
branch = master
连同@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