Trigger pipeline after merge request is merged/closed

Hi support team,

I’m wondering what our options are if we want to run a pipeline after a merge request is successfully merged or closed.

Looking at the docs I see there’s webhooks, is there another way to approach this?

Thanks,
Uyen Vu

You can define one or more jobs to run after the MR is closed with environment:on_stop

1 Like

Hi @rpadovani,

Thank you for your suggestion. I am going to try this way.

Update: I have tested with environment:on_stop, it works even more than expectation. Below is all test cases for trigger pipeline (cleanup environment) when environment stop:

  • environment stop
  • merge done with branch is deleted
  • merge done with branch is not deleted
  • merge close
  • branch is deleted

Thanks,
Uyen Vu

1 Like

Hi @rpadovani,

As your answer that we can define one or more jobs to run. However it seems only accept 1 job to run.
For example, I have tried declare as below, error shows that on stop should be a string. Do you have any suggestion on this point?

environment:
on_stop: [job-1,job-2]

Thanks,
Uyen Vu

1 Like

Hi @uyenvt85

I am happy that you were able to make it working for your use cases.

Unfortunately, it seems my answer was partially wrong: you cannot run multiple jobs in a single on_stop command: https://gitlab.com/gitlab-org/gitlab/-/issues/22456

1 Like

Hi @rpadovani,

Thank you for your information. I am going to check if there is possible way to do it.

Update: I found a possible way by in the job is declared in on_stop, we could define trigger other jobs (Refer to https://stackoverflow.com/questions/56699829/how-to-trigger-a-specific-job-in-gitlab)

Thank you so much!

Regards,
Uyen Vu

1 Like