0
votes

I'm trying to set up different build jobs in Jenkins for different branches of a Gitlab repository. I'm using Gitlab web hook to trigger the build.

Here are the steps I followed to setup a web hook for Jenkins CI in Gitlab

  1. Go to the project
  2. Settings --> Integrations
  3. Under 'Project Services', I've selected 'Jenkins CI'
  4. Now I've checked the 'Active' checkbox
  5. Jenkins url : <jenkins url>
  6. Project Name : <jobname_on_jenkins>

and provided credentials.

In Jenkins, I've selected the under 'Build triggers', I've selected

"Build when a change is pushed to GitLab" and provided the branch filters.

Now, In Jenkins, I've created another job with branch filter as different branch name.

Now my question is, How do i setup a web hook in Gitlab to trigger a different Jenkins job when there is a change in a specific branch. I tried providing comma separated job names for the field 'Project Name' in Gitlab web hook for Jenkins CI but it's not allowing comma separated values there.

Other details:

Gitlab version : GitLab Enterprise Edition 10.8.7-ee 075705a

Jenkins version: 2.138.3

Plugins installed on Jenkins : Gitlab, Gitlab webhook

1
Why you are not using this from Webhook, Triggers, push event? docs.gitlab.com/ee/user/project/integrations/img/…dcalap
dcalap : I'm not sure if I understand your question. If you are talking about Build Triggers like SCM polling, I tried that but it has issues especially when we are checking out more than one SCM. This is because I'm using scripted Pipeline (pulling the Jenkinsfile from a SCM)Raj
I don't see why you have created another job, why not using just the job with the branches filter and create the webhook by adding this job? In the screenshot I referenced before, you just have to click on Add Webhook and add the job URL, the one that appears in the check Build when a change is pushed to GitLab. GitLab CI Service URL: your-job-urldcalap
Our requirement is to have one build job per branch hence I'm trying to create a new job for a specific branch. In fact, I've used the branches filter and using webhook for the job that we have already for 'master' branch. Now I need to setup another job which is specific to another branch.Raj

1 Answers

0
votes

Just use two webhook - in the field branch name specify the name of the branch