From 3098cb3dc7175c8f2c04993cff6dfe3f8c1af0fe Mon Sep 17 00:00:00 2001
From: Yana Kernerman <kernerya@gmail.com>
Date: Sun, 11 Aug 2024 20:05:48 +0200
Subject: [PATCH] adjust the rules for the jobs

---
 .gitlab-ci.yml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d51a9a4..472e116 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,8 +1,8 @@
 workflow:
   rules:
-    - if: >-
-        $CI_PIPELINE_SOURCE == "push"
+    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
       when: 'always'
+    - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME =~/main/
     - when: 'never'
 
 stages:
@@ -21,7 +21,7 @@ job_test_the_code:
 job_build_artifact:
   stage: build
   rules: # Conditions under which this job should run
-    - if: $CI_COMMIT_REF_NAME =~ /^.*$/  # Run this job for any branch or merge request event.
+    - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"  # Run this job only for merge request event into main.
       when: always
   image: registry.hub.docker.com/library/golang:1.21
   script:
@@ -35,7 +35,7 @@ job_build_artifact:
 job_publish_artifact:
   stage: publish
   rules: # Conditions under which this job should run
-    - if:   $CI_COMMIT_REF_NAME =~ /^.*$/ # Run this job for any branch or merge request event.
+    - if:  $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"  # Run this job only for merge request event into main.
       when: always
   image: curlimages/curl:latest # Custom image with curl
   tags:
-- 
GitLab