Automating a build with triggers
The best way to allow your CI build to trigger when you make changes to your code is to use a post-commit webhook. We've already looked at such an example in the GitHub Actions workflow. Let's try to automate the build with triggers in the case of Jenkins. We'll have to make some changes on both the Jenkins side and the GitHub side to do so. Let's deal with Jenkins first, and then we'll make changes to GitHub.
Go to Job configuration | Build Triggers and make the following changes:
Save the configuration by clicking on Save. Now, go to your GitHub repository, click on Settings | Webhooks | Add Webhook, add the following details, and then click on Add Webhook:
Now, push a change to the repository and you should see that the job on Jenkins will start building: