将 GitLab CI 配置为仅对特定标记运行测试



对于托管在GitLab上的Python项目,我配置了一个CI构建,如下所示。对于每次推送,CI 构建都会运行测试套件、样式检查并构建文档。当分支合并到 master 时,CI 构建会执行额外的步骤,将构建的文档推送到 GitLab 页面的托管站点。

我想配置另一个仅在候选版本上执行的作业 - 名称中包含rc的 git 标签。GitLab CI 参考文档包括对if: $CI_COMMIT_TAG的几个引用,但我正在努力理解如何将它们放在一起。

<小时 />
before_script:
- apt-get update -qy
- apt-get install -y ...
- pip3 install ...
- pip3 install --no-deps --ignore-installed .
test:
stage: test
script:
- make test
- make style
- make doc
pages:
stage: deploy
script:
- apt-get update -qy
- apt-get install -y ...
- pip3 install ...
- pip3 install --no-deps --ignore-installed .
- sphinx-build -b html docs/ public
artifacts:
paths:
- public
only:
- master
<小时 />

更新/解决方案

根据@danielnelz的回答,我能够提出以下工作解决方案。

before_script:
- apt-get update -qy
- apt-get install -y ...
- pip3 install ...
- pip3 install --no-deps --ignore-installed .
test:
stage: test
script:
- make test
- make style
- make doc
prerelease:
stage: test
rules:
- if: '$CI_COMMIT_TAG =~ /rc/'
script:
- make testrc
pages:
stage: deploy
script:
- sphinx-build -b html docs/ public
artifacts:
paths:
- public
only:
- master

您可以检查预定义的$CI_COMMIT_TAG是否在规则子句中包含 rc:

release:
stage: release
script:
- do release
rules:
- if: '$CI_COMMIT_TAG =~ /rc/'

最新更新