From a5d87d387b71535d5f1eadec7029240d1ca12de1 Mon Sep 17 00:00:00 2001
From: Yorick Peterse <yorick@yorickpeterse.com>
Date: Wed, 29 Apr 2020 16:53:02 +0200
Subject: [PATCH] Use MR SOURCE_BRANCH_NAME to prevent RC pipelines

When creating a merge request to merge release-tools/X into a stable
branch, using CI_COMMIT_BRANCH still results in a detached pipeline
being created, likely due to this variable not being set in that case.
To work around this we have to use CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
instead, which is always set to the value we'd expect.

This fixes https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/822
---
 .gitlab-ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3ba8df9b0d209..a5d5b91842821 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -30,7 +30,7 @@ workflow:
     # merge requests used for this merge a branch release-tools/X into a stable
     # branch. For these merge requests we don't want to run any pipelines, as
     # they serve no purpose and will run anyway when the changes are merged.
-    - if: '$CI_COMMIT_BRANCH =~ /^release-tools\/\d+\.\d+\.\d+-rc\d+$/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^[\d-]+-stable(-ee)?$/ && $CI_PROJECT_PATH == "gitlab-org/gitlab"'
+    - if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^release-tools\/\d+\.\d+\.\d+-rc\d+$/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^[\d-]+-stable(-ee)?$/ && $CI_PROJECT_PATH == "gitlab-org/gitlab"'
       when: never
     # For merge requests, create a pipeline.
     - if: '$CI_MERGE_REQUEST_IID'
-- 
GitLab