1

I know the similar question has been asked many time before. I am trying to integarte GitLab with Jenkins through webhook and have an error as mentioned in title. I found the answer as well as per my situation which is listed here

Gitlab+Jenkins through webhook it shows this error, how can I solve this?.

The thing which is not understanable for me right now is as per the suggested solution

For me the URL for webhook what I saw was wrong. It was https://JENKINS_URL/job/YOUR_JOB it should be https://JENKINS_URL/project/YOUR_JOB, changing the job to project solved my issue

I am not able to find a way that how I can change job URL from https://JENKINS_URL/job/YOUR_JOB to https://JENKINS_URL/project/YOUR_JOB within Jenkins to build job URL as per GitLab webhook settings.

Any help will be much appreciated. Thanks

Update - My Jenkins server is configured with URL http://JENKINS_URL:8080/

ZahidAsim
  • 11
  • 1
  • 3
  • Are you working on localhost? and also are you using the public GitLab or using an organization GitLab – Affes Salem Jun 14 '22 at 10:30
  • @Affes Salem - not working with localhost, Using Jenkins URL which is set in Jenkins Location. also using an organization GitLab npot public one. – ZahidAsim Jun 14 '22 at 12:30

2 Answers2

0

trying

  1. login to jenkins > Manage Jenkins > Configure System

in here, config your server jenkins enter image description here

after back to Dashboard > New Item > Freestyle project. In Build Triggers, select Build when a change is pushed to GitLab. GitLab webhook URL: X enter image description here

after Advanced > Secret Token > Generate. you have key Y

  1. login to gitlab, open your project. in your project click Settings choose Webhooks. paste X, Y in your config jenkins to here. enter image description here

click Test if gitlab noti: enter image description here

you are success!!!

  • Thanks @Kiu Kiu Duck Pea - I know the procedure how to configure the web hook, the only problem is with job URL. Somehow I need to change/cofigure job URL's like http://JENKINS_URL/project/YOUR_JOB insted of http://JENKINS_URL/job/YOUR_JOB. – ZahidAsim Jun 14 '22 at 10:06
  • in jenkins, url hook gitlab is default JENKINS_URL/project/YOUR_JOB, if you want override or instead Hook URL. you can try with github. – Kiu Kiu Duck Pea Jun 14 '22 at 10:19
  • @ZahidAsim do you have a reverse proxy or a Loadbalancer in front of Jenkins? – ycr Jun 14 '22 at 11:30
  • @ycr - no reverse proxy or load balancer in my setup. – ZahidAsim Jun 14 '22 at 12:07
  • https://plugins.jenkins.io/gitlab-plugin/#plugin-content-webhook-url – Kiu Kiu Duck Pea Jun 15 '22 at 09:46
  • @Kiu Kiu Duck Pea I can't use github, have to setup with GitLab only. Please suggest if you know how to setup job URL in Jenkins as JENKINS_URL/**project**/YOUR_JOB instead of JENKINS_URL/**job**/YOUR_JOB? – ZahidAsim Jun 15 '22 at 10:30
0

You don't need to reconfigure your Jenkins instance. What you should do is the following:

  1. Go to the Jenkins project you want to use;
  2. Go to Configure -> Build triggers section;
  3. See the name of the checkbox Build when a change is pushed to GitLab. GitLab webhook URL: <TARGET URL>

What you're looking for is the "TARGET URL" from step 3. See the screenshot for an example of such an URL. As you can see it has the needed project format: enter image description here