Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab execute stage conditionally

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?

like image 707
deepdive Avatar asked Oct 11 '16 23:10

deepdive


2 Answers

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  
like image 187
avolkmann Avatar answered Sep 20 '22 19:09

avolkmann


There's not currently a way to run a job depending on the environmental variables (you can always open a feature request!). You could use a simple Bash command to immediately exit if the environment variable doesn't exist, though.

Something like:

stages:   - build   - test   - deploy  build_project:   stage: build   script:     - cd ./some-dir     - build-script.sh   except:   - tags  # Run this only when NIGHTLY_TEST environment variable exists. nightly_regression_test_project:   stage: test   script:     - [ -z "$NIGHTLY_TEST" ] && exit 1;     - cd ./some-dir     - execute test-script 

If the variable doesn't exist the tests that follow it won't run. Otherwise, they will.

Hope that helps!

like image 37
Connor Shea Avatar answered Sep 17 '22 19:09

Connor Shea