Reputation: 23438
Is a GitLab CI job's list of tags somehow exposed to its script?
We want to make sure that our project builds in a variety of different build toolchains, so we have CI jobs for each toolchain we want to support. Build jobs select an appropriate runner by specifying the toolchain in the job tags, but any given runner might provide more than one toolchain, so the job script additionally needs to know which toolchain to run.
Right now, this means we're duplicating the selected toolchain in the job definition: once in the tag list, and once in the script. If we could get at the job's tag list from the script, we could extract the tag that specifies the toolchain automatically.
For example:
build-xcode13:
stage: build
tags:
- xcode-13.4.1
script:
- XCODE_VERSION=13.4.1 build-tools/ci-scripts/build-debug.sh
Note how "13.4.1" appears in both the tags and the script body. This seems unnecessarily error-prone when someone copy-pastes the job definition but forgets to update one or the other value. If we had the list of tags available, we could easily extract the version by scanning the tags for one that matches the pattern.
The only relevant predefined variable I could find is CI_RUNNER_TAGS
, but this turns out to list all the tags defined for the runner, not the tags specified in the job.
Another workaround: I suppose we're also sort-of duplicating the toolchain in the job's title, and CI_JOB_NAME
is exposed to scripts, so we could make the title contain the exact toolchain specification, but that's no more reliable than explicitly setting a variable in the script - what really matters is that the spec for runner selection matches what the script actually tries to use.
Upvotes: 2
Views: 514
Reputation: 1417
Not sure if I get you correctly. If just specifying the tag twice is the issue you can keep it as variable.
build-xcode13:
stage: build
variables:
XCODE_VERSION: 13.4.1
tags:
- xcode-$XCODE_VERSION
script:
- build-tools/ci-scripts/build-debug.sh
Let me know if this is not what you need. Will try to help and update the answer then.
Upvotes: 2