Is it possible to run a gitlab pipeline job only once, when a merge request is created?

875 views Asked by At

Is it possible to configure a job in a gitlab pipeline to only run once, when a merge request is created?

Using the rule "

'$CI_PIPELINE_SOURCE == "merge_request_event"'

" does not work, as it will also be triggered when there are new commits to the branch with the open merge request.

1

There are 1 answers

0
Adex0401 On

You can use workflow to manage your pipeline. For example:

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
    - if: '$CI_PIPELINE_SOURCE == "schedule"'

This workflow will only be triggered when merge, default branch commit, schedule