Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab Jenkins Webhook integration

So the purpose was to trigger a build on a Jenkins job after making a push to Gitlab Repo, Simple right?

After Downloading Gitlab pluging, setting up the project, still no luck. I get a 403 error.

like image 618
yokodev Avatar asked Apr 15 '19 16:04

yokodev


People also ask

Can Jenkins integrate with GitLab?

With GitLab's Jenkins integration, you can effortlessly set up your project to build with Jenkins, and GitLab will output the results for you right from GitLab's UI.

Can GitLab receive Webhooks?

GitLab Webhooks allows using Webhook notifications for all of the major lifecycle events in the software development process. It can trigger Webhooks for Code Push Events, Issue Changes, Comments, Merge Requests, Pipeline Events, Wiki Page Events, Deployment Events, Release Events, etc.


1 Answers

After some trial and error here is how I solved the issue:

Things I try:
Web hook fails when Jenkins Anonymous user does not have job/build permission
Need to document GitLab -> Jenkins authentication setup How Do You Troubleshoot the GitLab Integration Webhook Error "Permission you need to have (but didn't) hudson.model.Hudson"?

This are the steps that I follow to fix this error

"Hook executed successfully but returned HTTP 403... You are authenticated as anonymous Groups that you are in: Permission you need to have (but didn't) hudson.model.Hudson.Read...which is implied by hudson.security.Permission.GenericRead..."

Go to Jenkins>Manage Jenkins>configuration
go to the Gitlab section and make sure is like so: Make sure Enable authentication for 'project' end-point is activated After setting up all this test your connection and make sure is successfull.

On your Jenkins project go Configure > Build Triggers and select
Build when a change is pushed to Gitlab. Gitlab webhook URL...
also, make sure to generate the token in advanced settings

remember to generate the token in advanced settings
Now in Gitlab go to your Project>Settings>Integrations paste the URL you got in your Jenkins project, as well as the token generated in the Gitlab Build Triggers section, remove ssl verification Webhook conf

Now hit save and test your hook
Test hook

you should get 200 success message on Gitlab and on Jenkins a triggered Job:
GitlabSuccess hook
Jenkins initiated job
If that's not the case and you still get the 403, This are things you can do:

in Gitlab add a Jenkins user to your project (the one you're trying to get the webhook triggered from). This time it should work!!! gitlab members

Troubleshooting

If it still not working another helper you can use is to add a logger to Jenkins go to Jenkins > Manage Jenkins > System log

  • add a new log recorder. Type in the name of the logger
  • add the loggers on the input field. Start typing gitlab or webhooks,
    anything related to Gitlab or webhooks :)
    loggers loggers conf hit save and start seeing whats going on when you hit the hook from Gitlab logs
like image 196
yokodev Avatar answered Sep 24 '22 06:09

yokodev