sri*_*sri 6 github gitlab gitlab-ci devops
如果条件为真,我想运行依赖作业。我们在 git 实验室中是否具有这种可行性。当我使用 DEPLOY 变量手动触发测试作业时,依赖项应该运行,否则跳过依赖项。我不想在构建阶段保持状况。
build:
stage: build
when: manual
script:
- echo build
test:
stage: test
when: manual
dependencies:
- build
if [ $deploy = 'true' ]
script:
- echo test
Run Code Online (Sandbox Code Playgroud)
Sim*_*ner 11
Gitlab 文档是一个很好的起点,尤其是规则部分。
规则关键字可用于在管道中包含或排除作业。
规则按顺序评估,直到第一场比赛为止。匹配后,作业将包含在管道中或从管道中排除,具体取决于配置。如果包含在内,则该作业还添加了某些属性。
这意味着您可以使用规则进行此类逻辑参与,在您的情况下,它看起来像
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
Run Code Online (Sandbox Code Playgroud)
我不确定第二条规则是否需要。但我强烈建议您查看 GitLab 文档中的以下指令:
| 归档时间: |
|
| 查看次数: |
8831 次 |
| 最近记录: |