New CI_COMMIT_BRANCH variable for use in only/except
Problem to solve
As explained in #57075 (closed) and #57076 (moved), the comingling of branch names, tag names, and special keywords in the "simplified" only/except clauses or refs:
clauses result in unexpected behavior at times.
At present, the only way to workaround the issue (as shown in #57075 (closed)) and truly run a pipeline only on a specific tag or branch is to use the variables:
clause. The $CI_COMMIT_TAG
variable provides an opportunity to test for tag refs:
only:
variables:
- $CI_COMMIT_TAG =~ /^my\-tag\-pattern$/
But the only way to properly test for branch refs is to check for $CI_COMMIT_TAG
to be blank and $CI_COMMIT_REF_NAME
to have a value:
only:
variables:
- $CI_COMMIT_REF_NAME == "master"
except:
variables:
- $CI_COMMIT_TAG
This is verbose and cumbersome.
Target audience
Anyone who wants a job to run only on branches, or only on specific branches, or only on branches that match a specific pattern, and want to do it in 3 lines of YAML instead of 6.
Proposal
Add a new variable $CI_COMMIT_BRANCH
that only has a value if the ref being run in the pipeline is a branch, and then has the value of the branchname.
So $CI_COMMIT_TAG
and $CI_COMMIT_BRANCH
would be mutually exclusive; only one of them would have a value for any given pipeline.