CI: Variables for groupd jobs' index and total
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Problem to solve
If there's a need to use grouped job's index, such things need to be added to .gitlab-ci.yml:
.template:
script: ...
1/2 job:
extends: .template
variables:
GROUP_INDEX: 1
2/2 job:
extends: .template
variables:
GROUP_INDEX: 2
Proposal
Similar behaviour is implemented in parallelized jobs (taken from documentation):
-
CI_NODE_INDEXIndex of the job in the job set. If the job is not parallelized, this variable is not set. -
CI_NODE_TOTALTotal number of instances of this job running in parallel. If the job is not parallelized, this variable is set to 1.
Considering that we already have these variables when defining jobs (1/2), they might be simply translated to predefined variables.
Corresponding to the parallelized jobs variables names would be CI_GROUP_INDEX and CI_GROUP_TOTAL
With such approach there might be much smaller jobs' description:
.template:
script: echo $CI_GROUP_INDEX
1/2 job:
extends: .template
2/2 job:
extends: .template
In my company there are groups of 20 jobs where we have to define Indexes manually in .gitlab-ci.yml
Links / references
Edited by 🤖 GitLab Bot 🤖