Reputation:
The question GitLab do not run CI/CD pipeline when creating new merge request is not a duplicate: I am asking about ".gitlab-ci.yml" rules, but that question has no answers about this.
On an issue page I click "Create Merge Request" --> A new pipeline is started automatically.
Do not run a pipeline on merge request creation
.default_rules:
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
when: manual
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- "**/*.{py,c,cpp}"
- .gitlab-ci.yml
- poetry.lock
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
changes:
- "**/*.{py,c,cpp}"
- .gitlab-ci.yml
- poetry.lock
- if: $PIPELINE_TYPE == "multi-project-pipeline"
Upvotes: 1
Views: 3408
Reputation:
SOLUTION
Do not run a job on Merge Request creation:
# .gitlab-ci.yml
your_job_name:
rules:
- if: $CI_COMMIT_BEFORE_SHA == "0000000000000000000000000000000000000000"
when: never
A LITTLE USEFUL BONUS
Full rules to avoid duplicate pipelines (just in case if someone needs this):
rules:
# Prevent creating duplicate pipelines because pipelines are already created for PUSH events.
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
# Do not run after Merge Request closing.
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: never
# Do not run on Merge Request creation.
- if: $CI_COMMIT_BEFORE_SHA == "0000000000000000000000000000000000000000"
when: never
# When to run:
- if: $CI_PIPELINE_SOURCE == "push"
changes:
# If the code has changed
- "**/*.py"
Upvotes: 4