Gitlab execute stage conditionally
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
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!