2

I know how to make specific jobs to run only on certain branches, but I would like to set a global rule for the entire pipeline config, so I don't have to set it in each job separately. Is that possible?

I'm currently putting this rule at the very top of the .gitlab-ci.yml file:

# Define rules that the entire pipeline should only run for the given branch
rules:
  - if: '$CI_COMMIT_BRANCH != "some-custom-branch"'
    when: never

but my pipeline fails with this error:

enter image description here

And all the documentation I can find is only about defining branch rules in specific jobs, but not on global state level.

Milkncookiez
  • 6,817
  • 10
  • 57
  • 96

1 Answers1

2

You can set rules for the entire pipeline by using the global workflow:rules: key

workflow:
  rules:  # only run pipelines on `main` branch
    - if: $CI_COMMIT_BRANCH == "main"
sytech
  • 29,298
  • 3
  • 45
  • 86