Add AND and OR operators for variable expressions in GitLab CI/CD
Problem to solve
only/except
are powerful primitives, but today are limited to only one case - either a single condition such as
job:
# use regexp
only:
- /^issue-.*$/
# use special keyword
except:
- branches
Adding multiple items does an "implied OR
" such that
job:
# use regexp
only:
- /^issue-.*$/
- master
Will build on branches that match the RegEx OR the master
branch
Intended users
Further details
This will be an excellent iteration for more complex use cases for only/expect, but will not be as wide of a solution as the flexible ruleset. Both will have impacts on how users can control which jobs run when, but have points where both are useful
Proposal
Allow a user to specific AND
and OR
conditions explicitly in a variable expression.
Use a well-known pattern of &&
for AND
and ||
for OR
. This will produce the ability for use cases such as:
Run on a job on master - AND on tags
job:
stage: publish
script:
- ./do-publish.sh
only:
- tags && master
Run a job on based on two different variables
only:
- $VARIABLE1 =~ /^content.*/ || $VARIABLE2 =~ /thing$/
AND
and OR
Complex logic with only:
- $VARIABLE1 =~ /^content.*/ || $VARIABLE2 =~ /thing$/ && $VARIABLE3
Permissions and Security
This will not change anything about the permissions or security for variables or the .gitlab-ci.yml
Documentation
This will require a documentation update with details AND clear examples.