Jenkins github plugin returns error 400 “Hook should contain event type”

戏子无情 提交于 2019-12-11 11:14:39

问题


At my company we have a Github Enterprise instance keeping all of our source in line, and Jenkins servers to do continuous integration. I'm using the Jenkins github plugin on Jenkins, and installing a service on Github to call MYJENKINS/github-webhook.

I would see the POSTs arriving from github on the jenkins server, but nothing would happen. The access log reports a 400 error being returned to github.

To find out what was being returned, I put tcpdump on the port. I now see that Jenkins is returning "Error 400 Hook should contain event type". It returns that for all repository events.

I can probably capture the github POST payload with tcpdump, but haven't done that yet.

My only guess at the moment is that our Github Enterprise installation is an earlier version than what is expected by the Jenkins github plug-in.

Update: As an experiment, on Github, I changed the call from a Service ("Jenkins github plugin") to a Webhook, but using the same URL MY_JENKINS/github-webhook/. THAT succeeds, is parsed successfully by the github plugin, and triggers the jobs that are watching a project/branch.


回答1:


Github Enterprise should have webhook functionality built-in, so I'm a little unsure what you mean when you say you're installing a service on Github.

You can set up new webhooks by going to the following tab:

https://github-enterprise.com/my-org/myrepo >> Settings >> Webhooks & services

Here is a screenshot:

The other place to check is the settings in Jenkins, to make sure that it is set up to work with Github.

Jenkins >> Manage Jenkins >> Configure System >> Find: GitHub Plugin Configuration

In here, you need to provide your credentials for Github as well as the Github api url:

https://<github-enterprise.com>/api/v3/


(You might be able to leave the 'Custom Github API URL' unchecked, but I haven't had good success with that.)

Here is a screenshot:

The 'Credentials' would be an access token from Github.

Github >> Personal settings >> Personal access tokens

It's been a while since I've done setup like this, so feel free to correct me if I'm wrong about anything.



来源:https://stackoverflow.com/questions/36609629/jenkins-github-plugin-returns-error-400-hook-should-contain-event-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!