Restrict a Job to Commits on a Branch
This example allows Release to run only for commits on main, while other jobs can run for commits on any branch.
-
Open Administration > Job Executors and edit each executor that could run the job.
-
Set Applicable Jobs to:
"Job" is not "Release" or on branch "main" -
Preserve any existing project or job restrictions by combining them with the expression in parentheses. For example, an executor dedicated to
tutorial-issuesuses:"Project" is "tutorial-issues" and ("Job" is not "Release" or on branch "main")
-
Save and test Release on
main, then on a new commit made only on a feature branch. The first succeeds; the second fails because the executor is not applicable. An ordinary job such as Check should run in both cases.
Apply the restriction to every executor the job could select. An unrestricted alternative executor can otherwise run it.
For ordinary builds, on branch "main" checks whether the commit is in main's history. A build launched from another branch can therefore pass when that branch points to a commit already on main. This is not an exact check of the build's selected branch name. For pull-request builds, executor applicability is checked against both source and target project/branch contexts.