Imagine you're using Gitlab to host your source code and want to trigger a Jenkins pipeline/job when you open a merge request on specific branches. In this guide we'll explain all that you need to do that.
Now, let's pretend we want to trigger the pipeline on a MR from feature/* to develop.
1) Install the "Generic Webhook trigger" plugin on Jenkins
2) In your pipeline configuration section, enable the plugin:
3) In Post Content Parameters section, you have to add these variables:
branch | $.object_attributes.source_branch |
merge_status | $.object_attributes.state |
body | $ |
5) In Optional filter section, insert the following:
6) Go to Gitlab, inside your Repository -> Settings -> Integrations
In the URL section insert: https://<jenkins_url>/generic-webhook-trigger/invoke?token=<your_token>
and below, enable the flag: "Merge request events"
Done!
You can test if your job/pipeline starts clicking on Test button, and choosing Merge Request events.