19

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.

Philippe Thiers
  • 303
  • 1
  • 3
  • 6

3 Answers3

15

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.

Jakub Kania
  • 15,665
  • 2
  • 37
  • 47
  • How can I parse the request with the script? Where I have to place the script? – ar099968 Jun 20 '18 at 14:38
  • 1
    @CescoBagnoli you need a web server that is accessible to your gitlab ci instance and some server side scripting to do it. You could use Lambda. You could use this gh project: https://github.com/MelwinKfr/gitlab-webhook-translator – Jakub Kania Jun 20 '18 at 15:44
12

This is now possible. This has been introduced in GitLab 11.6.

Nicolas Pepinster
  • 5,413
  • 2
  • 30
  • 48
4

For the moment, no. You should subscribe the issue to see if and when they will be available (and if your company is a enterprise customer, maybe you can contact them to ask to prioritize the implementation)

abd3721
  • 1,374
  • 1
  • 11
  • 10
rpadovani
  • 7,101
  • 2
  • 31
  • 50