gitlab CI: don't run MR pipelines in forks
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 29 Apr 2024 22:43:55 +0000 (08:43 +1000)
committerduna.oh <duna.oh@samsung.com>
Thu, 20 Feb 2025 02:28:08 +0000 (11:28 +0900)
Commit originally by Simon Ser in wayland/wayland-protocols!305.

Currently our CI setup has a downside: for each push on a merge
request, two pipelines are triggered. The first is triggered in
the context of the forked repository, and the second is triggered
in the context of the MR in the parent repository.

Replace the workflow rules with the ones in the official docs [1],
so that a branch pipeline isn't triggered when a MR exists for that
branch.

[1]: https://docs.gitlab.com/ee/ci/yaml/workflow.html#switch-between-branch-pipelines-and-merge-request-pipelines

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
.gitlab-ci.yml
.gitlab-ci/ci.template

index d524c64eaf581224dde5ba9e0e98b696bc369a25..e4b739ac31960b9c623e87acefadb3c8708c5589 100644 (file)
@@ -29,8 +29,10 @@ stages:
 
 workflow:
   rules:
-    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
-    - if: $CI_PIPELINE_SOURCE == 'push'
+    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
+    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
+      when: never
+    - if: $CI_COMMIT_BRANCH
 
 variables:
   # The upstrem repository we will check for images
index 520144ba8abe746fe59670eaaebb895f8d257988..799e06d744b4503de97fdbe291c4f0c6dfb9569b 100644 (file)
@@ -29,8 +29,10 @@ stages:
 
 workflow:
   rules:
-    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
-    - if: $CI_PIPELINE_SOURCE == 'push'
+    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
+    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
+      when: never
+    - if: $CI_COMMIT_BRANCH
 
 variables:
   # The upstrem repository we will check for images