Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins-Build when a change is pushed to GitHub option is not working

Jenkins is running on localhost. I have my repository in GitHub. I have the option to 'Build when a change is pushed to GitHub' checked.

When I click 'Build Now', build is done successfully, no issues there. But when am committing code to my repository, auto build is not happening. I can access GitHub from my system as the repository is public and I believe even Jenkins should be able to detect it. I know there is a polling option but I want Jenkins to build when change is detected in repository(as this is what we have been trying to achieve).

Configuration:

Jenkins 1.615

Git Plugin 2.3.5

Git Client Plugin 1.17.1

————————————————————————————————————————————

EDIT: "Build when a change is pushed to GitHub" option has been renamed to "GitHub hook trigger for GITScm polling" in most recent version of GitHub plugin. (thanks to @smrubin's feedback.)

like image 797
Anuj Balan Avatar asked Jun 01 '15 15:06

Anuj Balan


People also ask

How do I push changes to GitHub after Jenkins build completes?

In Jenkins execute shell under Build, creating a file and trying to push that file from Jenkins workspace to GitHub. Download Git Publisher Plugin and Configure as shown below snapshot. Click on Save and Build. Now you can check your git repository whether the file was pushed successfully or not.

Why Jenkins build is not triggering?

If the Jenkins job does not trigger, start by checking the logfile for any exceptions. Next, ensure everything is working correctly, confirm the following points: Polling SCM is enabled (no schedule is necessary, so that field can be left empty) Refer to Git plugin for instructions.


2 Answers

I suspect you missed the webhook url.

Besides checking the Build when a change is pushed to GitHub option, you should also add the webhook url into your Github repository to get the Auto trigger mechanism to work and here is how:

Go to your Github repository:

Settings--> Webhooks&Services-->Service--> Add Services--> Choose "Jenkins (GitHub plugin)"

Then fill in the Jenkins hook url with your jenkins url like this: http://your_jenkins_url/github-webhook/ enter image description here


And, VERY IMPORTANT, since you are installing your jenkins server in your localhost, please be aware that you shouldn't fill in above Jenkins hook url like http://localhost:8080/github-webhook/ because Github is not able to recognize localhost or 127.0.0.1 or 192.168.*.*.

Either you should use an externally accessible DNS name or an IP address, which can be recognized by Github.

like image 151
mainframer Avatar answered Sep 24 '22 17:09

mainframer


I had the same problem and solved it. The problem was that the URL had to end with a /. Meaning:

http://<jenkinsurl>:8080/github-webhook/

http://<jenkinsurl>:8080/github-webhook

(Notice the missing / at the end.)

like image 26
AskYous Avatar answered Sep 24 '22 17:09

AskYous