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
More on GitLab CI
How does GitLab CI/CD work at a high level?BeginnerWhat is a GitLab Runner and what executors exist?IntermediateWhat are the types of runners (shared, group, project) and tags?IntermediateWhat are workflow rules and how do they prevent duplicate pipelines?AdvancedHow do artifacts and cache differ in GitLab CI?IntermediateWhat does `needs:` do and how does it create a DAG pipeline?Intermediate