Day 25 of #90DaysOfDevOps
Automating Job Builds
Build Periodically
This option is used to run the jobs at scheduled time.
This field follows the syntax of cron (with minor differences). Specifically, each line consists of 5 fields separated by TAB or whitespace:
MINUTE HOUR DOM MONTH DOW
| MINUTE | Minutes within the hour (0–59) | | --- | --- | | HOUR | The hour of the day (0–23) | | DOM | The day of the month (1–31) | | MONTH | The month (1–12) | | DOW | The day of the week (0–7) where 0 and 7 are Sunday. |
In our configuration, we've specified five stars with a single whitespace, indicating that the job runs every minute.
Apply and Save the job. After applying and saving the job configuration, wait for a minute to witness the automatic job initiation, denoted in the console output as "Started by timer."
Poll SCM
Jenkins will check if there are any new commits to the repository mentioned the "Source Code Management" section at periodic time. If there is a new commit then only Jenkins will build/run the job.
Similar to the "Build Periodically" option, our configuration here also specifies five stars with a single whitespace, indicating that Jenkins connects with the GitHub repository every minute to check for new commits.
We can see that the build has "Started by an SCM change".
Note that this is going to be an expensive operation for CVS, as every polling requires Jenkins to scan the entire workspace and verify it with the server.
GitHub hook trigger for GITScm polling
This option is widely used for automating the build process, as it initiates the job only upon receiving a trigger from GitHub following a successful commit, ensuring that your Jenkins job only runs when necessary, thus optimizing resources and improving efficiency.
This integration between Jenkins and GitHub allows for seamless continuous integration and delivery (CI/CD) pipelines, ensuring that your builds are automatically triggered as soon as changes are pushed to your GitHub repository. This not only saves time but also helps maintain the integrity and reliability of your development process by ensuring that builds are always based on the latest changes.
How to setup webhook in GitHub?
Navigate to your GitHub repository settings.
Select "Webhooks"
Click on "Add webhook" and provide your credentials.
Add your Jenkins URL in the "Payload URL" field as:
http://public-ip:8080/github-webhook/
.Choose content type as
application/json
.Select desired events to trigger the webhook (e.g., "Send me everything").
Click on "Add webhook"
- In Jenkins, select "GitHub hook trigger for GITScm polling" in the build triggers options, then apply and save.
Now, any changes made to your GitHub repository will automatically trigger the job build.
You'll notice in the console output that the build is initiated with the message "Started by GitHub push by basavaraj-teli."
Congratulations! You've successfully automated the build process.
Subscribe to my newsletter
Read articles from Basavaraj Teli directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Basavaraj Teli
Basavaraj Teli
Aspiring DevOps engineer, working on DevOps projects to gain practical knowledge. I write technical blog post on DevOps to share my knowledge with fellow tech enthusiasts.