Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: Github webhook does not trigger any job

Tags:

jenkins

I try to configure Jenkins. I want a simple behavior: trigger a build on new pull request.

I cannot understand what I missed...

Jenkins version: 2.89.2

At https://ci.mysite.fr/configure :

enter image description here

Still no build triggered:

enter image description here

At https://ci.mysite.fr/job/test-back/configure : enter image description here

On Github, Webhook is sent and well received by Jenkins:

enter image description here

Nginx Log says the same:

enter image description here

Help please!

like image 688
Benoit Mariaux Avatar asked Jan 05 '18 16:01

Benoit Mariaux


People also ask

Why is my webhook not working?

Webhook requirements Another common reason why your webhooks could not be working is that you're not fulfilling the total requirements for consuming them. I once had an experience where I was receiving the webhooks but the request body was empty. It turned out that my server had to parse the raw request stream.


2 Answers

Some things to check when debugging this sort of thing:

  • Check your Jenkins logs to see whether or not Jenkins is receiving the hook and deciding not to take action for some reason.
  • Check Jenkins security by clicking Manage Jenkins -> Configure Global Security. Open things up as much as you're comfortable doing and see if that changes anything.
  • Ensure that you're pushing changes to the master branch. For simplification, consider using ** as your branch specifier while you're getting this to work.
  • Ensure Git is properly configured on your Jenkins host by clicking Manage Jenkins -> Global Tool Configuration
  • Make sure the user whose credentials you provided can manage hooks and pull from the repo you're interested in.
  • Run the job manually in Jenkins, ensure that it works.
  • After you run the job, it should show up as an option in Protected Branches/Required Statuses. In your repo, click on Settings->Branches, select your branch in the Branches section, click Require Status Check to Pass before merging option, and your job should show up in the list which appears.
like image 190
Bryan Cross Avatar answered Nov 15 '22 10:11

Bryan Cross


Webhooks are arguably the most difficult Jenkins feature to test without prior experience, because of gotchas like these (probably their list is incomplete):

  1. New git commit / git push must be made for each pipeline build (repeating a previous one won't trigger a new build even if webhooks are already set up correctly - see below).

  2. First build made after setting up webhook correctly must be manual (no bootstrap from the webhook itself is possible).

  3. First build made after setting webhook correctly must succeed completely for the changes to take effect and for webhooks to start working. This will also cause Jenkins to miss all incoming requests made during the first build of a newly created pipeline.


More info

  1. Please be warned that it is not possible to trigger a build using the same build conditions again (at least using a webhook). Therefore you might have a correct webhook setup already, but not find out that it works unless you create a new git commit and push it to the remote repo on Github. If your try to repeat some old push over and over again, by simply pressing the "Redeliver" button in the Recent deliveries section on Github's Webhooks / Manage webhook page, Jenkins will never move beyond the "poke" repo stage, as it requires SCM changes to be detected in order to trigger a new build:
Received PushEvent for https://github.com/mirekphd/<REPO_NAME> from <GITHUB_IP> ⇒ <JENKINS_URL>/github-webhook/

Apr 16, 2021 9:42:12 PM INFO org.jenkinsci.plugins.github.webhook.subscriber.DefaultPushGHEventSubscriber$1 run
Poked <REPO_NAME>

Apr 16, 2021 9:42:13 PM INFO com.cloudbees.jenkins.GitHubPushTrigger$1 run
SCM changes detected in <REPO_NAME>. Triggering #236

For further info on points 2) and 3): see original source.

like image 34
mirekphd Avatar answered Nov 15 '22 09:11

mirekphd