Gitlab CI / CD执行特定阶段而不是所有阶段

时间:2020-01-13 09:18:16

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

我的gitlab-ci.yml文件中有几个阶段,

例如:

stages:
  - one
  - two
  - three

是否可以运行指定的阶段?在Makefile中,它称为“目标”。我想在不同的情况下执行不同的阶段。例如:

if [ <condition 1> ]; then
  run all stages;
if [ <condition 2> ]; then
  run stage "one"; 
if [ <condition 3> ]; then
  run stages "two" and "three"; 
fi

1 个答案:

答案 0 :(得分:1)

您可以使用if规则在工作级完成此任务。

此外,stage只能包含一个作业。因此,请在您的.gitlab-ci.yml中创建3个作业,每个阶段创建一个作业,并配置如下规则(请查看文档以获取更多示例)ex:

stages:
  - one
  - two
  - three

job_one:
  stage: one
  script: "echo Hello, stage one"
  rules: 
    - if: '$VAR == "string value"'

job_two:
  stage: two
  script: "echo Hello, stage two"
  rules: 
    - if: '$VAR == "string value"'

job_three:
  stage: three
  script: "echo Hello, stage three"
  rules: 
    - if: '$VAR == "string value"'