Reputation: 105
I would like to write a pipeline and include some default values that could be overridden by the user in the project CI/CD settings.
Could I do something like the .gitlab-ci.yml bellow? It's not clear in the documentation...
variables:
VAR: $VAR || "default"
Or the user set tis value in the settings, or use the default value.
regards
Upvotes: 6
Views: 20623
Reputation: 1224
Variables defined in .gitlab-ci.yml are overwritten by variables defined on the project level:
try-job:
image: ubuntu:20.04
variables:
VAR1: 'var 1 set in gitlab-ci.yml'
VAR2: 'var 2 set in gitlab-ci.yml'
script:
- echo $VAR1;
- echo $VAR2;
When setting VAR2 variable manually during Pipeline trigger to var 2 set in project cicd variable
https://gitlab.com/mouson-gitlab-playground/gitlab-ci-parallel-test01/-/jobs/1821982396
The order of precedence for variables is (from highest to lowest):
ref: https://docs.gitlab.com/ee/ci/variables/index.html#cicd-variable-precedence
Upvotes: 9