Hello,
I have been trying to make a job’s tags set dynamicly depending on a variable but to no effect.
I’m writing a .include-nuget-ci.yml that defines two jobs : .buildNuget and .copyNuget. The point of this file is to be included in .gitlab-ci.yml files in many different repos (on a self-managed GitLab). The idea is to have as much of the jobs definitions possible in the .include-nuget-ci.yml file so that the .gitlab-ci.yml jobs just extends from one of these 2 jobs and can stay as short and easy to implement as possible (so setting up GitLab CI on a repo is easy, fast and consistent).
The catch is that the Nuget can be built in configuration Debug or Release and this configuration defines on which runner the job should run. If we build a Nuget in Debug config, it needs to run on the runner that has the “Debug” tag. If no configuration has been explicited, it needs to default to building in Release configuration and run on the runner with the “Release” tag.
So I tried to implement the following :
In the .gitlab-ci.yml, we can define the following job :
MyNuget1:Build:
extends: .buildNuget
variables:
SOLUTION_DIR: "." # Path to the dir containing the .sln file
PROJECT_PATH: "MyNuget1" # Path to the dir containing the .csproj
MSBUILD_CONFIGURATION: "Debug" # Optional var. If not here, default to "Release"
And in the .include-nuget-ci.yml, the .buildNuget starts like so :
# Job to build a Nuget
.buildNuget:
stage: Build
# Map the configuration used to the tags for the gitlab runner
variables:
JOB_TAG: ${MSBUILD_CONFIGURATION:-Release}
tags:
- $JOB_TAG # Run on the gitlab runner corresponding to the specified configuration ; if no configuration defined, default to Release configuration and tag
But this implementation doesn’t seem to work. I get the following warning on GitLab :
This job is stuck because of one of the following problems. There are no active runners online, no runners for the protected branch, or no runners that match all of the job’s tags: ${MSBUILD_CONFIGURATION:-Release}
Maybe this syntax doesn’t work to set a default value ? I have only seen it in a forum.
Maybe the variable JOB_TAG is evaluated before the variable MSBUILD_CONFIGURATION too ?
Maybe the job’s tags are evaluated before its variables ?
If you have any idea on how to fix this warning or a different solution to my problem.
Thanks for your help.