4
votes
  • I have setup a local instance of Jenkins on my computer, and I can access it through - "http://localhost:8080".
  • Created a Public Git repository, and added my ASP.NET MVC project there.
  • Also configured Jenkins to build the project, and it does the job very well.

However, this is a manual trigger. I mean, the build gets triggered only when a user clicks on "Build Now" in Jenkins console.

Actually, my requirement is to trigger a build when the changes are committed and pushed. (that means, "Commit and Push" while checking-in changes).

I referred to a lot of blogs and posts, and came to know about Git hooks. I also tried creating "post-receive" hook. I created a hook at the location where source code is mapped (For example, "E:\Git\test-jenkins.git\hooks").

#!/bin/bash
curl POST "http://localhost:8080/job/Test-Jenkins/build" --data delay=0sec

But this doesn't work. A build is never getting triggered on "Commit and Push". when I try copying the URL directly in the browser, it triggers a build, so I believe there is no issue with the URL. But the script itself is not getting executed.

Could anyone please suggest how to solve this problem?

Any help on this much appreciated.

2

2 Answers

2
votes

It's because Github server will not be able to reach the Jenkins server hosted on local, to trigger the build.

You will either need a static IP address or you need to map a DNS entry to your dynamic IP. Also, you need to open the port 8080 for external access. Only then GitHub will be able to reach your local instance with its webhook.

Hope it helps:)

0
votes

I think that you should use "webhook & services" in your repository settings in Github. Please see the image below:jenkins + github

To implement it, you have to have a public domain for your Jenkins