Skip to content
Latchkey

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.

Pipeline Editor
This GitLab CI configuration is invalid:
jobs:test config key may not be used with `rules`: only

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

.gitlab-ci.yml
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.

.gitlab-ci.yml
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; treat only/except as legacy.
  • Add a top-level workflow:rules to control when pipelines run at all.
  • Preview rule outcomes in the Pipeline Editor against each ref/source.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →