Recently in a Gitlab-CI pipeline I needed to dynamically include several variables that lived inside a yaml-file. The file that needed to be included was defined as a CICD-variable coming from an external API-call that triggered the CI-pipeline.
The file were called after version-numbers, e.g. .gitlab/vars/1.0.yml or .gitlab/vars/2.0.yml. This was their content:
variables:
LONG_VERSION: "1.0.0"
SHORT_VERSION: "1"
more: variables
These files were included in the pipeline using the include keyword:
include:
- local: .gitlab/vars/$VERSION.yml
This way, I can define “externally” (via the API-call to trigger a pipeline), what variables are to be loaded:
curl --request POST \
--form token=TOKEN \
--form ref=main \
--form "variables[VERSION]=1.0.0" \
"https://gitlab.example.com/api/v4/projects/123456/trigger/pipeline"