Skip to main content

Machine Intelligence

Configuring Jenkins Jobs by Using CRON

Istock 869275910 Two Men Look At Computer Code Together (resized)

Today, I’d like to walk you through configuring a Jenkins job automation through C jobs and its various choices.

Before jumping in, I’ll shed some light on what Jenkins is.

Understanding Jenkins

Jenkins is an open-source integration tool that allows continuous development, testing, and deployment of newly created codes. Jenkins plugins cover everything from version control systems, build tools, and code quality metrics to build notifiers. Many open-source plugins are available, making Jenkins very easy to use.

What is a CRON Job?

A CRON job is an instruction that repeatedly schedules a task for a particular time. CRON is the ideal option for ongoing tasks and performs non-interactive tasks in the background. A daemon is constantly inactive and awaits a command request to perform a specific task. A CRON job could save time by performing tasks automatically.

Use Cases of CRON

To execute specific instructions automatically, we occasionally need to schedule repetitive tasks. We can schedule any task or job to run after a particular set of hours, a certain number of times per month, on a certain day or date, etc. They are time-based task schedulers, which are utilized for practically all task scheduling.

CRON in Jenkins

In the Jenkins job’s “Configure” option, we’ll want to navigate to the “Build Trigger” tab, where we’ll see the checkboxes for “Poll SCM” and “Build Periodically.” These are the options where we must be familiar with CRON syntax and its function to configure our Jenkins Build.

If we want to execute the job every time something is pushed into the repository from the last build, we will choose the “Poll SCM” option from the “Build Trigger” tab. This could be handled either by writing a CRON job to check the changes in the repository after every 10 or 15 minutes, or we can use a plugin or utility, which will automatically signal our job when our repository changes.

Another scenario would be if something changes in our repository, yet we still want to activate the job at regular intervals. We don’t need to deal with version control system modifications in this instance. Instead, we want to set off our work in accordance with the conditions of our job. If the task is simply about reporting, downloading, and dumping into the database, then we should select the “Build Periodically” option in the “Build Trigger” tab.

Creating the Job

To create a job, go to Jenkins and click on “New Item.” Add the project. It can either be a “Freestyle project” or whatever project we want.


Cron Job 1

Cron Job 2


Configure the job by adding the details. Add the job details from the “General” tab.

Configuring the Job

Schedule the build from the “Build Triggers” tab, write the CRON, and check the “Build Periodically” box.

Cron Job 3

Build the job to test and check if everything is working well. Once we build the job, the results will be as shown below.

Cron Job 4

CRON Syntax

If we want to run the build every 30 minutes, enter the following CRON schedule.

Cron Job 5

Below are different syntax to be aware of:

  • Minute (0-59) – what minute of the hour the job will run on.
  • Hour (0-23, where 0 is midnight) – what hour the command will run in the 24-hour clock.
  • Day of the month (1-31) – the day of the month we want the job to run on (g., the first of each month).
  • Month (1-12) – tells the month when the job should run. We can number or name the month as well. (i.e., April, May, June, etc., could also be written as 4, 5, 6, etc.).
  • Day of the week (0-7, where 0 or 7 are both Sunday) – the day of the week when we want to run our job. It can also be a number or name.


CRON Job Examples

If we want to run the build every day at 10:00 am:

Cron Job 6

If we want to run the build every 6 hours:

Cron Job 7

If we want to run the build every Saturday and Sunday at 2:00 pm:

Cron Job 8

To conclude…

Setting up scheduled jobs will be practical and help us avoid missing the action on time if we have to execute it manually. Utilizing CRON jobs within Jenkins is a great way to automate the jobs.

For more information on Jenkins or CRON, contact our commerce experts today.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sirisha Maddineni

Sirisha Maddineni is a Senior Technical Consultant at Perficient. She is very passionate about exploring new technologies.

More from this Author

Follow Us