GitLab "rules" / "only" / "except" Errors - Jobs Run or Skip Wrong
Your job ran when it should not have, was skipped when it should have run, or triggered a duplicate pipeline. The cause is almost always a rules/only/except logic or mixing error.
What this error means
Either a hard validation error ("jobs:test may not be used with rules: only"), a "duplicate pipeline" warning on every MR, or jobs silently running on the wrong ref or event.
This GitLab CI configuration is invalid:
jobs:test config key may not be used with `rules`: onlyCommon causes
Mixing rules with only/except
rules is mutually exclusive with only/except in the same job. GitLab rejects a job that declares both.
Detached MR + branch pipeline duplication
Rules that match both push and merge_request_event create two pipelines per MR. Without $CI_PIPELINE_SOURCE guards you get duplicates.
Wrong variable or operator in a rule
Comparing $CI_COMMIT_BRANCH when the pipeline source is a tag (where it is empty), or using =~ against a non-regex, makes a rule never match.
How to fix it
Pick one mechanism - prefer rules
rules is the modern replacement; do not combine it with only/except in the same job.
test:
script: make test
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == "main"'Avoid duplicate MR pipelines
Use workflow rules so a branch pipeline does not run alongside the MR pipeline.
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS'
when: never
- if: '$CI_COMMIT_BRANCH'How to prevent it
- Standardize on
rules; treatonly/exceptas legacy. - Add a top-level
workflow:rulesto control when pipelines run at all. - Preview rule outcomes in the Pipeline Editor against each ref/source.