如何只在分支上手动触发gitlab CI作业并始终自动在master上?

问题描述 投票:1回答:1

我有一个页面作业,我想在分支上运行手动,但在master上自动触发:

pages:
  stage: deploy
  cache:
    paths:
      - public
  script:
    - scripts/pages.sh
  artifacts:
    paths:
      - public
    expire_in: 2 days

所以我想要一个组合:

  only:
    - master
  when: always
  only:
    - branches
  except:
    - master
  when: manual

那可能吗?

gitlab-ci
1个回答
0
投票

您需要定义两个阶段。你可以复制/粘贴或使用锚点:

.deploy_stage: &deploy_stage
  stage: deploy
  cache:
    paths:
      - public
  script:
    - scripts/pages.sh
  artifacts:
    paths:
      - public
    expire_in: 2 days

deploy_manual:
  <<: *deploy_stage
  only:
    - branches
  when: manual

deploy_master:
  <<: *deploy_stage
  only:
    - master
© www.soinside.com 2019 - 2024. All rights reserved.