Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in integrating gitlab with jenkins

I have a project created and configured on private Gitlab v9.0 instance. I have imported this project on Jenkins v2.46.1, the connection with gitlab is successful. Afterwards, I tried to configure build trigger on push event from repo in gitlab. I have generated secret token for it on jenkins and added a webhook with Gitlab CI URL and secret token when I tried to test the webhook it returned me below exception

Hook executed successfully but returned HTTP 403 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Error 403 anonymous is missing the Job/Build permission</title> </head> <body><h2>HTTP ERROR 403</h2> <p>Problem accessing /project/tapp-builder-service. Reason: <pre> anonymous is missing the Job/Build permission</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/> </body> </html>

Can anyone please help me solving this?

like image 530
vsbehere Avatar asked Apr 14 '17 07:04

vsbehere


People also ask

Can we integrate GitLab with Jenkins?

You can trigger a build in Jenkins when you push code to your repository or create a merge request in GitLab. The Jenkins pipeline status displays on merge requests widgets and on the GitLab project's home page.

How do I integrate my GitLab repository to my Jenkins project?

Go to Manage Jenkins -> Configure System and scroll down to the 'GitLab' section. Write a custom connection name, enter the GitLab server URL in the 'GitLab host URL' field and click Add -> Jenkins button. Then, fill required fields as shown below with the Jenkins Access API Token which we created in GitLab before.

How do I add GitLab credentials to Jenkins?

On the Global Configuration page in Jenkins, in the GitLab configuration section, supply the GitLab host URL, e.g. https://your.gitlab.server. Click the 'Add' button to add a credential, choose 'GitLab API token' as the kind of credential, and paste your GitLab user's API key into the 'API token' field.


2 Answers

The best way to configure this is

  1. Jenkins global configuration ->

Require authorization for /project endpoint Copy userid and API key for a Jenkins user who has authorization to run the job

  1. Create a webhook on GitLab to trigger the job

  2. Then use HTTP basic auth (Below format):

http://user:apikey@gitlab/project/jobname

like image 57
Manikandan Ram Avatar answered Sep 27 '22 18:09

Manikandan Ram


You can either add a special user in Jenkins for this and configure the Webhook in GitLab accordingly or you can uncheck the checkbox "Enable authentication for '/project' end-point" in the GitLab section of the global Jenkins configuration. But this should be unchecked by default.

like image 23
lax1089 Avatar answered Sep 27 '22 18:09

lax1089