How to Set Up Automation Build Triggers
Build Periodic
Used to trigger the Jenkins jobs irrespective of code change.
The build is scheduled based on the crontab
It is not meant for CI/CD
How to set up build periodic trigger
Go to any project in Jenkins and click on "Configure."
Scroll down and look for the "Build Triggers" section.
Select Build periodically option
We can click on “?” for help in syntax of cron
We can also use this link: https://crontab.guru/ for help.
Enter the syntax in the field
Here “ * * * * *” means build will run every minute.
Click on "Apply" and then "Save."
Build will execute every minute
GitHub Webhook
Used to trigger Jenkins job whenever there is any commit happened in the remote repository.
GitHub Webhook has to be configured in the remote repository by using the Jenkins URL
Used to implement CICD.
How to set GitHub Webhook trigger
Go to any project in Jenkins and click on "Configure."
Scroll down and look for the "Build Triggers" section.
Select “GitHub hook trigger for GITScm polling” option
In the GitHub repository, click on the settings button.
From left menu click on Webhooks
Click on Add Webhook
In the ‘Payload URL’ field, paste your Jenkins environment URL. At the end of this URL add /github-webhook/. In the ‘Content type’ select: ‘application/json’ and leave the ‘Secret’ field empty. Click on “Add Webhook”.
Add the Webhook and commit the changes in the repository
Build gets executed as soon we commit the changes.
PollSCM
It is used to trigger the build based on the crontab only if there is any changes happened in the source-code repository.
- i.e. if we set crontab to “* * * * *” and make some changes in source code repository, build will trigger based on the changes after every one minute.