Gitlab CI/CD 执行特定阶段而不是所有阶段
Gitlab CI/CD execute specific stages instead of all the stages
我的 gitlab-ci.yml
文件中有几个阶段,
例如:
stages:
- one
- two
- three
是否有可能运行指定阶段?在 Makefile 中它被称为 "targets"。我想在不同的情况下执行不同的阶段。例如:
if [ <condition 1> ]; then
run all stages;
if [ <condition 2> ]; then
run stage "one";
if [ <condition 3> ]; then
run stages "two" and "three";
fi
您可以使用 if 规则在作业级别执行此操作。
此外,一个 stage 只能包含一个作业。因此,在您的 .gitlab-ci.yml
中创建 3 个作业,每个阶段一个并配置这样的规则(查看文档以获取更多示例)例如:
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"'
我的 gitlab-ci.yml
文件中有几个阶段,
例如:
stages:
- one
- two
- three
是否有可能运行指定阶段?在 Makefile 中它被称为 "targets"。我想在不同的情况下执行不同的阶段。例如:
if [ <condition 1> ]; then
run all stages;
if [ <condition 2> ]; then
run stage "one";
if [ <condition 3> ]; then
run stages "two" and "three";
fi
您可以使用 if 规则在作业级别执行此操作。
此外,一个 stage 只能包含一个作业。因此,在您的 .gitlab-ci.yml
中创建 3 个作业,每个阶段一个并配置这样的规则(查看文档以获取更多示例)例如:
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"'