How do you run jobs conditionally on merge requests only?
BeginnerConceptGitLab CI
Answer
Use rules with $CI_PIPELINE_SOURCE == "merge_request_event". In MR pipelines, extra variables like CI_MERGE_REQUEST_IID and CI_MERGE_REQUEST_TARGET_BRANCH_NAME are available.
lint:
script: npm run lint
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
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`?IntermediateWhat are workflow rules and how do they prevent duplicate pipelines?AdvancedHow do artifacts and cache differ in GitLab CI?Intermediate