Once Jenkins installed successfully, now will see how to automatically create a build if any new commits in Github. Which helps to improvise your continuous integration setup with Jenkins. This approach will helpful to trigger a new build after changes made in code (repository), instead of building or polling manually in frequent interval.
To accomplish this, have to follow some steps initially, here will see each steps how to get it. I have referred plenty of guides which not updated or unclear. Will try to solve that and tried best to give easy and clear.
Very first step has to do is install Github plugin on Jenkins. You will need to download and install the GitHub plugin. Manage Jenkins -> Manage Plugins -> Available -> GitHub plugin.
After this is installed you can either create a new build or configure an existing build job. Since I already have one set up I will just modify it to use the GitHub hook. There are a few things that need to be changed.
First, you will need to add your github repo:
Then you will then have to tick the box indicated below – “Build when a change is pushed to GitHub”
Also note that Jenkins should have an SSH key already associated with the desired GitHub project. For more Refer : Github plugin
Almost we done. The final step is to head over to GitHub and adjust the settings for the project by creating a webhook for your Jenkins server. Select the repo you’re interested in and click Settings. Make sure you are the admin for the repo, otherwise you can’t do any modification on it. If you are not the admin, work with the admin and get it done or get the admin access and follow the step.
The GitHub steps are pretty straight forward. Open the “Integrations & Services” tab -> choose “Add Service” -> find the Jenkins (GitHub plugin option) and fill it in with a similar URL to the following:
- http://<Name of Jenkins server>:8080/github-webhook/
Make sure to tick the active box and ensure it works by running the “Test Hook”. If it comes back with a payload deployed message you should be good to go.