4

I've written a simple gitlab-ci.yml like this.

job1:
  script: 
  - echo hello

Currently, the script got triggered whenever a commit is pushed to any branches.

How can I configure gitlab-ci to make this script triggered only after a merge request is merged into the master branch?

I cannot find how to achieve my goal in the only key word.

There's a Merge request events option in Settings -> Integrations page, which seems to provide the function that is close to what I want.

enter image description here

Brian
  • 12,145
  • 20
  • 90
  • 153
  • Duplicate? https://stackoverflow.com/questions/43918324/trigger-jobs-in-gitlab-ci-on-merge-request – podliy16 Nov 02 '18 at 06:59
  • That question is about triggering jobs BEFORE a merge request, which is a little bit different from mine. – Brian Nov 02 '18 at 07:17

1 Answers1

0

Based on the question here, I use gitlab-webhook-translator to trigger the script after a merge request is merged.

The key point here is to set the condition to ":object_kind == 'merge_request' && :object_attributes.work_in_progress === false && :object_attributes.state == 'merged'".

Another thing I want to mention is that we have to check Allow requests to the local network from hooks and services box in gitlab so that we can use gitlab wbehooks.

enter image description here

I use a simple web server to inspect the requests sent from gitlab. This is how I discovered :object_attributes.state == 'merged' option for the condition of gitlab-webhook-translator.

Brian
  • 12,145
  • 20
  • 90
  • 153