Search code examples
gitlab-ci

Trigger Gitlab CI pipeline on merge


my .gilab-ci.yml file contains this:

deploy_to_prelive:
  artifacts: {}
  tags:
    - mytag
  stage: deploy
  script:
    - echo "Deploy"
  environment:
    name: prelive
    url: https://example.com
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "prelive"'

while i create a merge request from another branch into this branch, the script runs.

But i expect to run the script only when i approve the merge and hit the "Merge" button.

Are there any rules that i can use for that?


Solution

  • If you wish to trigger this pipeline when merge has been done on your prelive branch, you should change the trigger rule.

    deploy_to_prelive:
      artifacts: {}
      tags:
        - mytag
      stage: deploy
      script:
        - echo "Deploy"
      environment:
        name: prelive
        url: https://example.com
      rules:
        - if: '$CI_COMMIT_BRANCH == "prelive" && $CI_PIPELINE_SOURCE == "push"'