Tech Blog

Coding

How to Automatically Trigger Builds at Scheduled Time Using Jenkins?

By Keshav TN3 min read
← Back to blog

In continuous automation suite execution, it is important to run test cases every day and at certain time intervals to ensure that the product is working seamlessly in production.If any cases fail, the QA is alerted and the issue is fixed before a customer encounters the issue. 

Cron Patterns helps to achieve automation by scheduling builds in Jenkins according to the requirement of the frequency with which the certain case should be triggered.

When creating a job in Jenkins,we can set the frequency according to the job that will be triggered. 

Before we understand how this works, let’s first see what are the most common parameters used –

Minutes – Minutes in an hour (0-59) 

Hours – Hours in a day (0-23)

DayMonth – Days in a month (1-31) 

Month – Months in a year (1-12)

DayWeek – Day of week (0-7), 0 and 7 are Sunday

The most common Cron Patterns used for scheduling jobs are explained below – 

1)  * * * * *

This will run every minute, all the time: When we wish to run jobs every single minute, we use this pattern

2) 0 * * * * 

This will run at minute zero, every hour (at hourly interval): The number of minutes can be changed accordingly by changing 0 to how many ever minutes you wish to schedule the build

3) 15 * * * *

This will also run hourly but run at minute 15 instead – it would run like this –  (00:15, 01:15, 02:15): 

4) 30 2 * * *

This will run once a day, at 2:30am: we can change the hours accordingly to change the timing at which the build will be triggered.

5) */10 * * * *

Division operator is also used when we want the build to be run every 10 minutes:

This is usually the most common scheduling pattern used as it tests the stability of the product by running the job very frequently and in a way mimics the customer usage of the product too.

6) 0 5-10 * * *

A range can be specified using the dash (-). This will be repeated every hour between 5:00 and 10:00 a.m.

7) 0 0 2 * *

Sometimes we have requirements where we want the job to be triggered only every month – this is where the above cron pattern is used – This will run once a month, on the second day of the month at midnight (January 2nd, 12:00 am, February 2nd, 12:00 am):

8) 0 * * * 1

When the job is required to be triggered only on certain days of the week, we use the above pattern – Which will run every hour on Mondays only.

We can replace this with other numbers between 0 and 7 to run on any day of the week accordingly.

9) 0,10,20 * * * *

We can use multiple numbers separated by commas for the minutes – This will run three times every hour, at minutes 0, 10 and 20:

This is used when we are trying to reproduce a customer issue where a customer is facing inconsistency in the issue,but the issue is reproducible one out of 3 times; to test this scenario we make use of this pattern.

Thus, this is how builds in Jenkins are scheduled to run accordingly with the use of simple logic of CRON expressions.

Keep reading

You may be interested in

Browse all articles →
Active Directory Federation Service
July 5, 20235 min read

Active Directory Federation Service

Active Directory Federation Service (ADFS) uses claims-based identity model to maintain application security and to implement federated identity. ADFS is a concept of Windows Server operating system, that provides users with single sign-on access to the application, those are located across organizational boundaries. For Example: We have 2 organizations – Organization 1 and Organization 2. […]

By Abinash MishraRead More →
Remote Access to Microsoft SQL Database Server
April 5, 20232 min read

Remote Access to Microsoft SQL Database Server

Remote access to a SQL server is important because it allows users to access the server from anywhere, at any time. This enables remote workers to access the data they need when they need it, even if they are not physically in the same location as the server. It also allows IT admins to access […]

By Malkeet SinghRead More →
Types of Load Balancer in AWS
February 6, 20235 min read

Types of Load Balancer in AWS

What is Load Balancing ? Load balancing is a critical component of any scalable and highly available Cloud or On-premise architecture. It helps distribute incoming traffic across multiple servers, improving the availability and scalability of a website or application. In the cloud, load balancing is offered as a service by various cloud providers such as […]

By Keerthik ShenoyRead More →