简体   繁体   中英

Webhook from GitLab to Jenkins returns HTTP 404

I'm trying to make it so my Jenkins job builds automatically when I push to a gitlab repository. For this, im using the 'GitLab Plugin' for Jenkins.

Here is what's working:

  • I can build the job manually.
  • Jenkins can access my GitLab project using an API key.

Here is the problem: I configured my Jenkins project and it gave me a URL to use with a GitLab webhook. I also use a secret token.

In GitLab, I add this webhook using the EXACT same url that the plugin gives me, and I add the secret token as well. I disable SSH. Upon testing, it returns HTTP 404 with the following message:

 Hook executed successfully but returned HTTP 404 <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Error 404 Not Found</title> </head> <body><h2>HTTP ERROR 404 Not Found</h2> <table> <tr><th>URI:</th><td>/project/UnitTestFramework%20-%20Gaspar%20Tamas</td></tr> <tr><th>STATUS:</th><td>404</td></tr> <tr><th>MESSAGE:</th><td>Not Found</td></tr> <tr><th>SERVLET:</th><td>Stapler</td></tr> </table> <hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.30.v20200611</a><hr/> </body> </html>

For reference the URL looks something like this:

http://jenkins.server.address.com:8282/project/My%20Project%20Name

with server name and project name replaced of course, whitespaces are escaped using %20. I don't see what could be wrong with this URL, as the GitLab plugin gives it to me, there can be no typo or anything.

I found a solution myself browsing SO. It bypeasses the GitLab plugin entirely as I could not get that URL to work. See this answer, it worked for me.

If the link ever goes down here is the idea, use this webhook url:

http://(jenkins_user):(jenkins_api_token)@(jenkins_server_address):(port)/job/(job_name)/build?delay=0sec

Actually if you set up your Jenkins Job as the GitLab plugin suggests it, except you use this webhook instead of the one that the plugin gives, commit status will be updated in your GitLab anyways.

Be aware that the answer above will expose your password or API key in the url / Webhook page.

If you don't want to work around the plugin, you have to define a user in Jenkins and configure this user on the GibLab Webhook.

If it's only for testing, you can also simply disable authentication on Jenkins Global Settings, but this is obviously not recommended for anything serious.

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.

As said here on the Jenkins Gitlab Plugin Github

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM