How can one use !reference in variables block and then extend the list of entries?
For example, I want to be able to do something like
variables:
!reference [.common_variables, variables]
FOO: "bar"
At the moment I get an error in the GitLab linter:
This GitLab CI configuration is invalid: (): did not find expected key while parsing a block mapping at line 1 column 1
P.S. Note that this question is specifically about !reference.
.common_variables into a separate file that I include in my pipeline.extends: mechanism is out of scope of this question. It does work, but it has a weird behaviour that one also gets an extends variable in the environment, see GitLab: use `extends` in `variables`variables: !reference [.common_variables, variables]
Is the correct way to reference, however gitlab yml structure will not support additional definitions after the !reference keyword.
My advice would be to have a more specific definition in your variables file that uses anchors to share the common varaibles.
e.g:
in 'variables.gitlab-ci.yml':
.common_variables: &common_variables
COMMON_VAR: value
.variables:Example-job
variables:
<<: *common_variables
FOO: "bar"
in '.gitlab.ci.yml':
Example-job:
variables: !reference [".variables:Example-job", "variables"]
script:
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With