How to write .gitlab-ci.yml job to run only in merge-request is approved

88 Views Asked by At

I am checking on a solution where GITLAB CI job has to run only when merge-request is approved.

test_c: stage: test script: - echo "This job tests something. It will only run when all jobs in the" - echo "build stage are complete." rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

This works when the merge request is created but not when it is approved.

1

There are 1 best solutions below

0
On

You could check the predefined variable

CI_MERGE_REQUEST_APPROVED

rules: 
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_APPROVED == "true"