Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - (private subnet) WebHook with Github does not trigger automatic build

Problem :

I am working on a CI setup to configure github - Jenkins web hook for triggering builds with code commits on github. Below are the current configuration details

  • My Jenkins is inside an AWS private subnet
  • I have plugin: "GitHub Web Hook" configured with API URL, Username and OAuth token, Test Credentials gives a success message.
  • I have "Build when a change is pushed to GitHub" selected under "Build Triggers"

Jenkins job works perfectly with the manual build. But it does not work (automatic build trigger) when a code commit is done on the github.

Need Help on:

  1. How can I debug in detail about this situation, if the "Git hub webhook" configuration test worked, can I say git hub is able to connect to my Jenkins which is in private or it does something else to test ?
  2. Please rectify / guide on the steps to get it working
like image 422
Chandan Nayak Avatar asked Jun 15 '15 14:06

Chandan Nayak


2 Answers

I'll expand cody.codes comment given this one has sat idle for a while. You can configure a webhook payload delivery service such as smee.io which will intercept the webhooks that GitHub fires.

This Jenkins article outlines the setup instructions in detail, but the simplified overview is:

  1. GitHub event such as an SCM change occurs, and triggers a webhook to be fired to your configured Smee channel
  2. Smee channel (blue box on the image below) receives this webhook
  3. Jenkins server is subscribed to your custom smee channel, spots that there is a new event there, and triggers your job.

Simplified visual overview of the communication between GitHub, Smee, and Jenkins

Jenkins only makes an outbound connection in this setup (which is required to subscribe to your Smee channel) so your Jenkins server can remain behind your firewall.

like image 119
Andy Shearer Avatar answered Nov 08 '22 18:11

Andy Shearer


After spending some hectic hours, I have got it to a working state. Below is just a summary of what I have done:

  • You can do it in two ways, Poll SCM or WebHooks (explained here)
  • JenkinsURL/job/job-Name/scmPollLog is the place to check for polling logs
  • I have moved my Jenkins into a public subnet (github needs to talk to jenkins)
  • Go to https://github.com/settings/tokens and create your access token
  • On Jenkins > Manage Jenkins > Configure system > configure GitHub Web Hook, API URL - "https://api.github.com" Username - your github user name, OAuth token which was created above - Test it for success!!
  • Navigate to job configuration and under Build Triggers, select "Build when a change is pushed to GitHub"
  • Go to https://github.com/yourID/repoName/settings/hooks and Add a webhook
Payload URL - http://jenkinsIP:port/github-webhook/
Content type - application/x-www-form-urlencoded
Secret - none
Which events would you like to trigger this webhook? - Just the push event
Active > Add webhook

You can check commit a change into the github and github shall send a POST request to your jenkins server which will trigger the build. You can check the logs in Recent Deliveries section.

enter image description here

If this same can be done for a private jenkins server like using port forwarding, or any other way. Please update.

like image 25
Chandan Nayak Avatar answered Nov 08 '22 17:11

Chandan Nayak