github - 如果 gitlab 管道中的条件为真,则运行依赖项作业

标签 github gitlab devops gitlab-ci

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

    相关文章:

    ssl - 如何使用 Datadog 监控 ssl 证书?

    devops - salt 栈 : Requiring packages installed before formula executed

    git - 使用 git 时未发现 Repo fatal error 且无法推送到 github

    git - 不同 repo 中的不同 Joomla .gitignore 文件

    linux - 如何在 Ubuntu 上的 iptables 中删除/解锁我的服务器 IP?

    ios - 如何使用 Xcode 9 添加 gitLab 存储库?

    git - 删除 BitBucket 上的大文件

    git - 如何使用NPM 安装特定的Git 分支?

    git - "fork"和 "push upstream"对 GitHub 意味着什么?

    git - 在 GitLab 的 CI/CD 系统中,如果作业在我的 fork 中,我如何阻止它运行,并且只允许它在 merge 到主仓库时运行?