What are workflow rules and how do they prevent duplicate pipelines?
AdvancedConceptGitLab CI
Answer
A branch with an open merge request can get two pipelines per push: a branch pipeline and a merge request pipeline. Top-level workflow:rules decide whether a pipeline is created at all, so you pick one.
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
This runs MR pipelines for branches with an open MR, and branch pipelines otherwise.
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?IntermediateHow do `rules:` work and how do they replace `only/except`?IntermediateHow do artifacts and cache differ in GitLab CI?IntermediateWhat does `needs:` do and how does it create a DAG pipeline?Intermediate