How to trigger Jenkins Multi-Branch Pipeline with Gitlab Webhook

This is a longer response to the question comment above about merge requests, and due to length I'm posting it as an answer rather than a comment.

Multibranch pipeline does not support Gitlab merge request hooks. More accurately, the gitlab plugin does not support this. If you add a merge request webhook and test it you will get the response..."Merge Request Hook is not supported for this project". Going to the documentation you find...

"Pipeline Multibranch jobs

Note: There is no way to pass external data from GitLab to a Pipeline Multibranch job, so the GitLab environment variables are not populated for this job type. GitLab will just trigger branch indexing for the Jenkins project, and Jenkins will build branches accordingly without needing e.g. the git branch env var. Due to this, the plugin just listens for GitLab Push Hooks for multibranch pipeline jobs; merge Request hooks are ignored." https://github.com/jenkinsci/gitlab-plugin#pipeline-multibranch-jobs

Very unfortunate. You can at least create a classic job of type "Pipeline", and use the "Pipeline script from SCM" option which will rely on a Jenkinsfile in the repo. This will support scripted or declarative, or a blend of the 2. This means you can point this at a Jenkinsfile you've already created in Blue Ocean (only to find that you can't do a merge request for this because a pipeline created in Blue Ocean is of course always multibranch). You can then configure this classic pipeline job to trigger on merge requests using the job configuration. You will need to use the plugin steps in the script to updateGitlabCommitStatus and acceptGitLabMR as required. This does at least result in the ability to view the pipeline runs in the more modern Blue Ocean UI. And the pipeline link in your Gitlab MR will also direct you to the same UI.


You need to install Gitlab Plugin on Jenkins.

This will add a /project endpoint on Jenkins. (See it in Jenkins => Administrate Jenkins => Configure System => Gitlab )

Now add a webhook on your Gitlab project => Settings => Integrations. (or in older Gitlab version : Gitlab project => Wheel icon => Integrations, it seems you need to be owner of project in this case)

In Url : set http://*yourjenkins.com*/**project**(/*foldername*)?/*yourprojectname* and that's all, and click on "Add Webhook".

When you click on test on your webhook, it should trigger your jenkins pipeline build. (You should have a 200 http response)

It works without authentication in Gitlab plugin, configuration with authentication are welcome.


Use the GitLab Branch Source Plugin

There is a (still somewhat new) Jenkins plugin called GitLab Branch Source which provides many great features that I could not easily get set up without the plugin and which should easily accommodate the OP’s requirements.

For example, you can create a single “Multibranch Pipeline” Jenkins job, configure it to have the desired “GitLab Project” as its “Branch Source” and that will automatically create new Jenkins jobs for your project branches and new Jenkins jobs for your merge requests. The plugin can also take care of automatically installing a web hook on the GitLab project so that new branches, commits or merge requests will trigger Jenkins going forward.

All this is nicely configurable, for example, you can either opt-in or opt-out of the automatic web hook creation. Or you can specify that the merge request jobs should create and check out a local merge commit/result for testing.