gitjenkinsgitlabjenkins-pipelinemultibranch-pipeline

How to trigger Jenkins Multibranch Pipeline with Gitlab Webhook


I currently set up a Jenkins Multibranch Pipeline job that is based on a Git repository hosted on our GitLab server. Jenkins can read the branches in the repository and creates a job for every branch in the repository. But I can't figure out how to trigger the jobs with webhooks in GitLab.

My questions are:

  1. How can I trigger the creation of a new branch job in Jenkins from our GitLab server? I can't see a webhook for a new branch being pushed.

  2. How do I trigger the actual build job for a single branch? I can only add a webhook for push events but then I would have to add the branch name which I don't know how to do.

  3. How can I make sure that GitLab always triggers the "creation of the branch job" before a push to a branch triggers the build job itself.

What I tried so far is triggering the multi-branch job, but this has no effect and following this post does not work at all.


Solution

  • You need to install the GitLab Plugin on Jenkins.

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

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

    Set the URL to http://*yourjenkins.com*/**project**(/*foldername*)?/*yourprojectname* then click "Add webhook".

    When you click "Test" on your webhook it should trigger your Jenkins pipeline build (you should get a 200 HTTP response).

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