Skip to main content

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.

  1. Open Administration > Job Executors and edit each executor that could run the job.

  2. Set Applicable Jobs to:

    "Job" is not "Release" or on branch "main"
  3. Preserve any existing project or job restrictions by combining them with the expression in parentheses. For example, an executor dedicated to tutorial-issues uses:

    "Project" is "tutorial-issues" and ("Job" is not "Release" or on branch "main")

    Executor applicable-jobs restriction

  4. 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.

note

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.