Trigger jobs in gitlab-ci on merge request

Philippe Thiers picture Philippe Thiers · May 11, 2017 · Viewed 13.7k times · Source

It's posible run a job from gitlab-ci only on merge request? Now, we have a big monolitic project with heavy tests, but we only want to run the test before merging to the branch master.

Answer

Jakub Kania picture Jakub Kania · May 12, 2017

Well, it's not built in currently however it's not impossible to do it yourself. Gitlab allows to trigger a job. It also supports webhooks on merge requests. However webhooks don't support variable in URIs and triggers can't read request body so you'd have to create a script that will act like a middle-man here:

  1. Webhook on merge request calls to your script
  2. Script parses the request and calls a triggers in gitlab with correct REF
  3. Trigger runs the job that is marked with;

    only: -triggers

It's a bit hacky but it's working and easy to implement.