How do `rules:` work and how do they replace `only/except`?

IntermediateConceptGitLab CI
Answer

rules is a list evaluated top to bottom; the first match decides whether the job is added (when: on_success, manual, never, delayed). Conditions: if (CI variable expressions), changes (paths), exists. only/except are legacy and cannot be combined with rules.

deploy:
  script: ./deploy.sh
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      changes: [src/**/*]
    - if: $CI_COMMIT_TAG
      when: manual
    - when: never
All CI/CD questions Roadmap: GitLab CI/CD

More on GitLab CI