GitLab CI - 运行 文件内容更改时的管道
GitLab CI - Run pipeline when the contents of a file changes
我有一个包含多个项目的单一存储库(不是我的设计选择)。
当 "version" 文件更改时,每个项目都有一个 .gitlab-ci.yml
设置到 运行 管道。这很好,因为用户可以签入 stage
或 master
(用于热修复),然后创建构建并将其部署到测试环境。
问题是当用户从 master
合并到 stage
并提交回 stage
(以引入任何热修复)。这会导致所有管道 运行;即使对于没有实际内容更改的项目。
如何允许管道从 master
and/or stage
运行 但仅当 "version" 文件的内容发生变化时?比如当用户更改版本号时。
这里是 .gitlab-ci.yml
的一个例子(我有 5 个,mono-repo 中每个项目 1 个)
#
# BUILD-AND-TEST - initial build
#
my-project-build-and-test:
stage: build-and-test
script:
- cd $MY_PROJECT_DIR
- dotnet restore
- dotnet build
only:
changes:
- "MyProject/.gitlab-ci.VERSION.yml"
# no needs: here because this is the first step
#
# PUBLISH
#
my-project-publish:
stage: publish
script:
- cd $MY_PROJECT_DIR
- dotnet publish --output $MY_PROJECT_OUTPUT_PATH --configuration Release
only:
changes:
- "MyProject/.gitlab-ci.VERSION.yml"
needs:
- my-project-build-and-test
...等等...
我对 git、GitLab 和 CI/pipelines 还是个新手。任何帮助,将不胜感激! (我对更改单存储库没有什么发言权)
仅当文件 version
更改时,以下 .gitlab-ci.yml
才会 运行 test_job。
test_job:
script: echo hello world
rules:
- changes:
- version
见https://docs.gitlab.com/ee/ci/yaml/#ruleschanges
另请参阅
Run jobs only/except for modifications on a path or file
我有一个包含多个项目的单一存储库(不是我的设计选择)。
当 "version" 文件更改时,每个项目都有一个 .gitlab-ci.yml
设置到 运行 管道。这很好,因为用户可以签入 stage
或 master
(用于热修复),然后创建构建并将其部署到测试环境。
问题是当用户从 master
合并到 stage
并提交回 stage
(以引入任何热修复)。这会导致所有管道 运行;即使对于没有实际内容更改的项目。
如何允许管道从 master
and/or stage
运行 但仅当 "version" 文件的内容发生变化时?比如当用户更改版本号时。
这里是 .gitlab-ci.yml
的一个例子(我有 5 个,mono-repo 中每个项目 1 个)
#
# BUILD-AND-TEST - initial build
#
my-project-build-and-test:
stage: build-and-test
script:
- cd $MY_PROJECT_DIR
- dotnet restore
- dotnet build
only:
changes:
- "MyProject/.gitlab-ci.VERSION.yml"
# no needs: here because this is the first step
#
# PUBLISH
#
my-project-publish:
stage: publish
script:
- cd $MY_PROJECT_DIR
- dotnet publish --output $MY_PROJECT_OUTPUT_PATH --configuration Release
only:
changes:
- "MyProject/.gitlab-ci.VERSION.yml"
needs:
- my-project-build-and-test
...等等...
我对 git、GitLab 和 CI/pipelines 还是个新手。任何帮助,将不胜感激! (我对更改单存储库没有什么发言权)
仅当文件 version
更改时,以下 .gitlab-ci.yml
才会 运行 test_job。
test_job:
script: echo hello world
rules:
- changes:
- version
见https://docs.gitlab.com/ee/ci/yaml/#ruleschanges
另请参阅 Run jobs only/except for modifications on a path or file