Extend 'only' and 'except' to add environment variables and boolean logic
This is the original intent of #34785 (closed) that was then addressed differently, but the initial idea is valuable and allows to do more powerful improvements to Auto DevOps template (and also others).
Extending syntax, we add capabilities to select if a job should be executed or not if specific environment variables are set, extending
except. This is good since it allows to avoid creating the job if conditions are not met, saving a lot of runner resources.
Extend only the complex scope of
except, using the new keyword
variables that is in logical AND as it is now for
Note: This syntax change has to be considered alpha, and subject to change.
This is the proposed syntax:
only: variables: - $VAR1, $VAR2 - $VAR3 == 'yes'
VAR2 are set, or
VAR3 value is
- items on different lines are in logical OR
- items on the same line are in logical AND
AND has precedence over OR (as in most common cases)
$VARIABLE: variable is set
(does an empty variable match or not? probably yes but you proposed differently in your comments)
$VARIABLE == string: variable is equal to string
(do we want to allow also comparing between two variables?)
$VARIABLE ~= pattern or regex: variable matches the pattern/regex
Links / references
Make sure these are completed before closing the issue, with a link to the relevant commit.
Proposal from #23538 (closed)
The only and except parameters in .gitlab-ci.yml are very useful for limiting runs. I have a system where each build is an arbitrary subset of the possible large superset of builds (these are recipes to build other software - I only want to build any recipes in my repository that have changed). I can submit individual builds and use an environment variable to carry out the selected build. However, I can't limit the tags/platforms that it runs on. I am left with something of a hack: run all jobs for all platforms all of the time, but terminate non-matching platforms early based on the trigger variables. This still costs me machine spin-up time. If I bundle all platforms into one build, then the dependency build-out is unnecessarily constrained by waiting for all of the platforms to finish a given dependency - even if they don't use it.
I would like to propose that environment variable expressions be usable in the only/except parameter, so that they can be used to limit which jobs actually run on triggered builds.
- $TARGET_PLATFORM == some_hardcoded_tag
or, even cooler, relate to tags (check for membership?):
Alternatively, allowing trigger variables in the tags would be a good alternate to the functionality I'd like.