Nirman
Nirman

Reputation: 6783

Github + Jenkins >> How to trigger build on "Commit and Push" in code repository?

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.

Upvotes: 5

Views: 3639

Answers (2)

Nguyen Sy Thanh Son
Nguyen Sy Thanh Son

Reputation: 5376

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

Upvotes: 0

Arpit Aggarwal
Arpit Aggarwal

Reputation: 29266

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:)

Upvotes: 3

Related Questions