I try to connect Gitlab merge request webook with Jenkins and I got an error:
Error 403 No valid crumb was included in the request HTTP ERROR 403 Problem accessing /view/test-view/job/test-project. Reason: No valid crumb was included in the request
What I want to achieve?
- I try to use Gitlab Webhooks to trigger jenkins build when new merge request is created.
When jenkins build triggered by gitlab merge request webhook succeed then merge request from feature branch to master will be possible.
Everything seems fine, but I get this error when I test the merge request webhook.
What steps I've done already:
1. I've opened -> Gitlab -> my project -> Settings -> Webhooks
2. I set: URL, Secret Token and clicked on 'Add webhook' button
- URL - url to my project on jenkins:
- Secret Token (generated secret token in jenkins project view - this plugin is required https://plugins.jenkins.io/gitlab-plugin/)
Entire response that I get in Gitlab:
<html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Error 403 No valid crumb was included in the request</title> </head> <body><h2>HTTP ERROR 403</h2> <p>Problem accessing /view/test-view/job/test-project. Reason: <pre> No valid crumb was included in the request</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/> </body> </html>
How to fix this problem?
Found solution by myself.
I was pretty simple.
I needed to modify URL from /job/ to /project/ from:
After we install jenkins gitlab plugin:
This plugin has it's own REST API which is integrated with jenkins. And this REST API looks like this:
We can read more here:
Configuring per-project authentication
If you want to create separate authentication credentials for each Jenkins job:
- In the configuration of your Jenkins job, in the GitLab configuration section, click 'Advanced'
- Click the 'Generate' button under the 'Secret Token' field
- Copy the resulting token, and save the job configuration
- In GitLab, create a webhook for your project, enter the trigger URL (e.g.
https://JENKINS_URL/project/YOUR_JOB) and paste the token in the Secret Token field
- After you add the webhook, click the 'Test' button, and it should succeed