手动作业在某些分支可用,但在其他分支中被阻止

时间:2021-07-14 16:43:49

标签: gitlab gitlab-ci

.gitlab-ci.yml 文件中定义了三个主要阶段:testdeploy_testdeploy_integration。每次都执行第一阶段,同时其他阶段被拆分为主要部署 (actual) 和备用部署。

这个想法是当更改被提交到任何分支时,能够将应用程序部署到替代测试服务器和替代集成服务器。它适用于除 dev 分支之外的任何分支:

Pipeline stages

配置文件(为了更清晰起见做了截断)看起来是这样的:

image: ubuntu:18.04

stages:
  - test
  - deploy_test
  - deploy_integration

test:
  stage: test
  when: always
  script:
    - echo "Hi test!"

deploy_test_actual:
  stage: deploy_test
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"'
      when: manual
    - if: '$CI_COMMIT_BRANCH == "dev"'
      when: manual
  script:
    - echo "Hi!"

deploy_test_alternative:
  stage: deploy_test
  when: manual
  allow_failure: true
  script:
    - echo "Hi!"

deploy_int_actual:
  stage: deploy_integration
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"'
      when: manual
    - if: '$CI_COMMIT_BRANCH == "dev"'
      when: manual
  script:
    - echo "Hi!"

deploy_int_alternative:
  stage: deploy_integration
  when: manual
  script:
    - echo "Hi!"

问题:如何为 deploy_int_* 分行解锁 dev 个工作?

1 个答案:

答案 0 :(得分:1)

对于您的 dev 分支配置,deploy_int_* 任务取决于所有您的 deploy_test_* 任务的实现,包括不允许的 deploy_test_actual失败。

在任何其他分支上,deploy_test_alternative 是您 deploy_test 阶段中的唯一任务。由于此任务允许失败 (allow_failure=true),因此您可以从 Gitlab UI 手动启动任何 deploy_integration 任务。

我会考虑更新您的 .gitlab-ci.yml 文件:

deploy_test_actual:
  stage: deploy_test
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"'
      when: manual
    - if: '$CI_COMMIT_BRANCH == "dev"'
      when: manual
  allow_failure: true
  script:
    - echo "Hi!"