Gitlab execute stage conditionally

deepdive picture deepdive · Oct 12, 2016 · Viewed 18k times · Source

There are 3 stages - build, test and deploy in .gitlab-ci.yml.

A nightly regression test stage needs to be run - well nightly :)

Here's the relevant .gitlab-ci.yml code:

stages:
  - build
  - test
  - deploy

build_project:
  stage: build
  script:
    - cd ./some-dir
    - build-script.sh
  except:
  - tags

#Run this only when say variable 'NIGHTLY_TEST == True'. But HOW?
nightly_regression_test_project:
  stage: test
  script:
    - cd ./some-dir
    - execute test-script

Tagging daily to only run test stage is not preferable.

Any other idea?

Answer

Andreas Volkmann picture Andreas Volkmann · Jun 29, 2018

except and only can specify variables that will trigger them.

You can use the following in your .gitlab-ci.yml:

build1:
  stage: build
  script:
    - echo "Only when NIGHTLY_TEST is false"
  except:
    variables:
      - $NIGHTLY_TEST 

test1:
  stage: test
  script: 
    - echo "Only when NIGHTLY_TEST is true"
  only:
    variables:
      - $NIGHTLY_TEST