如果条件为真,我想运行依赖作业。我们在 git lab 中是否有这种可行性。当我使用 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 文档中的以下指令:关于github - 如果 gitlab 管道中的条件为真,则运行依赖项作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65564847/