New CI_COMMIT_BRANCH variable for use in only/except
Problem to solve
At present, the only way to workaround the issue (as shown in #57075) 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.
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.
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.
$CI_COMMIT_BRANCH would be mutually exclusive; only one of them would have a value for any given pipeline.