disable gitlab pipeline after merge request is accepted

Viewed 40

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.

1 Answers

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.

Related