运行 如果 gitlab 管道中的条件为真,则依赖作业
run dependency jobs if condtion is true in gitlab pipeline
如果条件为真,我想 运行 依赖作业。我们在 git lab.When 中是否具有这种可行性?我使用 DEPLOY 变量手动触发测试作业,然后依赖项应该 运行 否则跳过依赖项。我不想在构建阶段保持状态。
build:
stage: build
when: manual
script:
- echo build
test:
stage: test
when: manual
dependencies:
- build
if [ $deploy = 'true' ]
script:
- echo test
Gitlab 文档是一个很好的起点,尤其是 rules section.
The rules keyword can be used to include or exclude jobs in pipelines.
Rules are evaluated in order until the first match. When matched, the
job is either included or excluded from the pipeline, depending on the
configuration. If included, the job also has certain attributes added
to it.
这意味着您可以使用规则进行此类逻辑参与,在您的情况下它看起来像
build:
stage: build
when: manual
script:
- echo build
test:
stage: test
needs: ['build'] # dependency on previous build stage
script:
- echo test
rules:
- if: '$deploy == "true"' # when true, than run automatically
- if: '$deploy != "true"' # when not true, than run only manually
when: manual
我不确定第二条规则是否需要。但我强烈建议查看 GitLab 文档中的以下指令:
如果条件为真,我想 运行 依赖作业。我们在 git lab.When 中是否具有这种可行性?我使用 DEPLOY 变量手动触发测试作业,然后依赖项应该 运行 否则跳过依赖项。我不想在构建阶段保持状态。
build:
stage: build
when: manual
script:
- echo build
test:
stage: test
when: manual
dependencies:
- build
if [ $deploy = 'true' ]
script:
- echo test
Gitlab 文档是一个很好的起点,尤其是 rules section.
The rules keyword can be used to include or exclude jobs in pipelines.
Rules are evaluated in order until the first match. When matched, the job is either included or excluded from the pipeline, depending on the configuration. If included, the job also has certain attributes added to it.
这意味着您可以使用规则进行此类逻辑参与,在您的情况下它看起来像
build:
stage: build
when: manual
script:
- echo build
test:
stage: test
needs: ['build'] # dependency on previous build stage
script:
- echo test
rules:
- if: '$deploy == "true"' # when true, than run automatically
- if: '$deploy != "true"' # when not true, than run only manually
when: manual
我不确定第二条规则是否需要。但我强烈建议查看 GitLab 文档中的以下指令: