1

I have this problem that whenever a merge request is accepted some pipelines start to run.

We also have the same pipeline for pushing a branch to GitLab and also creating a new merge request.

This is my job :

build:
  stage: build
  script:
    - mvn $MAVEN_CLI_OPTS clean install -Dmaven.test.skip=true -P prod
  artifacts:
    expire_in: 800 mins 0 sec
    paths:
      - app.jar
      - Dockerfile
      - docker
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - /node_modules     
    policy: pull-push
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "master" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "develop"'
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - if: '$CI_PIPELINE_SOURCE != "push" && $CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_REF_NAME == "master"' 
    - if: '$CI_PIPELINE_SOURCE != "push" && $CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_REF_NAME == "develop"' 

I don't want the pipeline to run after the merge request is accepted.

Adam Marshall
  • 6,369
  • 1
  • 29
  • 45
Hani Bikdeli
  • 23
  • 1
  • 7

1 Answers1

-1

You should use only tags instead of rules to reduce complexity.

build:
  stage: build
  script:
    - mvn $MAVEN_CLI_OPTS clean install -Dmaven.test.skip=true -P prod
  artifacts:
    expire_in: 800 mins 0 sec
    paths:
      - app.jar
      - Dockerfile
      - docker
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - /node_modules     
    policy: pull-push
      only:
       - master
       - development
        refs: merge_requests
      except:
       - stage
       - prod

In this build stage will be triggered only from main and development branch, stage and prod branches are not permitted. So these were permissions, when this stage will be triggered is only when a MR is created.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 18 '22 at 18:18