Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

Problem : 

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

My Jenkins is inside an AWS private subnet

I have a 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:

How can I debug in detail about this situation, if the "Git hub webhook" configuration test worked, can I say git hub can connect to my Jenkins which is in private or it does something else to test?

Please rectify/guide on the steps to get it working

1 Answer

0 votes
by (50.2k points)

I would like to summarize how to set a webhook for an automatic build.

There are two ways to achieve this

 Poll SCM

WebHooks

Now we look into webhooks according to the question.

First, we need to check the polling jobs for this JenkinsURL/job/job-Name/scmPollLog is the place where you can check the jobs. Then move your Jenkins into a public subnet so that 

Github can be able to talk with Jenkins.

Now go to Github and create your access token then On Jenkins > Manage Jenkins > Configure system > configure GitHub Web Hook, API URL - "https://api.github.com" Username - your github user name, OAuth(allows an end user's account information to be used by third-party services) token which was created above- after this run the test and make it a success without having errors. Now 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

Then github will send a post request on your Jenkins server then it will trigger the builds automatically.

Browse Categories

...