With the help of webhooks we can configure Jenkins to automatically trigger a build for every code push/change to our code repository.
Follow the below steps to trigger builds with webhooks:
1. Change Job Configuration in Jenkins
– In General section, select GitHub project and enter the url for your repository.
– In Source Code Management section, add your GitHub repository url.
– In Build Triggers section, select GitHub hook trigger for GITScm polling.
2. Add Webhook in your GitHub repository
– Goto GitHub Repository -> Settings -> Webhooks
– Click on Add Webhook button
– Enter Payload URL:
https://jenkinsUrl/github-webhook/
If you are running Jenkins on your localhost server then follow the steps mentioned here to generate a public URL.
– Select Content type as “application/x-www-form-urlencoded”
– Select SSL Verification (Enabled/Disabled)
– Under Which events would you like to trigger this webhook?, select “Send me everything”
– Click on Add Webhook button to save the settings.
3. Push any code change to your GitHub repository.
4. Jenkins will automatically trigger a build for the project.