Here’s how making a commit to your selected Github branch can trigger a Jenkins build and how to set it up in your Jenkins server.
To start, you need to make sure your Jenkins installation is available to the internet or else it won’t work.
How Does It Work?
Jenkins uses a webhook. A webhook (or web callback) is a way for an app to provide other applications with real-time information. Meaning that GitHub will send a webhook to our Jenkins server. Our Jenkins application will build and test the changes and send the build status for the commit that was made.
GitHub Integration Plugin
You need to install a special plugin for Jenkins called “GitHub Integration”.
Follow these steps,
- Go to Manage Jenkins > Manage Plugins > Available.
- Use the search bar and search for “GitHub”.
- Search and select the plugin named “GitHub Integration”.
- Click on “Download now and Install after Restart”.
Setup
Follow these steps to create a job (if you haven’t already),
Check the “Github project” checkbox and place your Github repository URL link.
1 – Check the “Github project” checkbox and place your Github repository URL link.
2 – Under the Source Code Management section we select “git” and place our repository URL once again.
3 – Specify which branches you want to build. By default Jenkins will select the master branch for you.
4 – Now you can select your build triggers. The Github Integration plugin will add the “Github hook trigger for GITScm polling” option for you. Which means that every time Jenkins receives a PUSH GitHub hook (from the repository you defined in the Source Code Management section) it will trigger the polling login you previously defined.
After all that, just let GitHub know that it has to notify your Jenkins server every time there is a commit.To do this, go to GitHub repository > settings > Webhooks > Add webhook
Then fill the following information,
1 – In Payload URL place the Jenkins server URL with this format: “<PAYLOAD_URL>/github-webhook/”. Just by appending this “/github-webhook/” you are telling Jenkins to route the request to the GitHub plugin.
2 – Select the content type.
3 – Configure when GitHub should send events to this webhook.
4 – Check the “Active” box.
And you are done! Your Jenkins server will build according to how you configured the GitHub webhook. Any questions or comments send me a line at jcordoba@nearsoft.com.