gitlab ci: Run build job when manual or when master only

toni_maccaroni picture toni_maccaroni · Dec 5, 2017 · Viewed 18k times · Source

Is it possible to have a gitlab-ci file wheres a build job defined with the following requirements:

  • get executed when manual OR
  • get executed by master push

I thought of something like this, but this is poorly false:

build_jar:
stage: build
script:
  - echo "build jar"
artifacts:
  paths:
    - jar/path/*.jar
only:
  - master
when: manual

Only solution for me is to have two jobs, one for the master push and one a manual input. But the disadvantage is, that in gitlab it becomes confusingly

Answer

lukmdo picture lukmdo · May 24, 2018

I also did not find a way to do this in one block and had to use yaml anchors and split into two separate blocks:

.deploy_common:
# common config HERE

deploy_master_CD:
  extends: .deploy_common
  only:
    refs:
      - master

deploy_manual:
  extends: .deploy_common
  when: manual

OR all in one since GitLab 12.3 using rules

deploy:
  rules:
    - if: '$CI_COMMIT_REF_NAME == "master"'
    - when: manual