Schedule Your First Automation: A "Hello World!" Jenkins Freestyle Job with Periodic Builds

Divakar ChakaliDivakar Chakali
4 min read

Namaste Folk! 👋 Your automation aficionado is back, and today we're taking our "Hello World!" Jenkins journey a step further. In our previous exploration, we manually triggered a simple Freestyle Job. Now, we'll learn how to schedule that job to run automatically at specified intervals. This is a fundamental concept in automation, allowing you to execute tasks without manual intervention – the very essence of DevOps efficiency!

So, grab your virtual chai ☕ and let's dive into setting up a "Hello World!" Freestyle Job in Jenkins that triggers periodically.

Revisiting the "Hello World!" Freestyle Job (Quick Recap)

Before we schedule it, let's quickly remind ourselves of the "Hello World!" Freestyle Job, we created earlier. It's a simple job that, upon execution, prints the message "Hello World!" to the console output. This job serves as a perfect starting point for understanding scheduling.

If you haven't created this job yet, here's a quick rundown of the configuration steps:

  1. On your Jenkins dashboard, click "New Item".

  2. Enter a name (e.g., HelloWorldPeriodic) and select "Freestyle project". Click "OK".

  3. In the "Build" section, click "Add build step" and choose "Execute shell" (for Linux/macOS agents) or "Execute Windows batch command" (for Windows agents).

  4. In the command field, enter:

    • For "Execute shell": echo "Hello World!"

    • For "Execute Windows batch command": echo Hello World!

  5. Click "Save".

Or for detailed guide visit Setup "Hello World" - Free Style Job

Now, let's move on to scheduling this job.

Step-by-Step Guide: Setting Up Periodic Builds

Follow these steps to configure your "HelloWorldPeriodic" job to run automatically at a specified schedule:

Step 1: Open the Job Configuration

  1. On your Jenkins dashboard, locate your HelloWorldPeriodic job.

  2. Click on the job name to open its overview page.

  3. On the left-hand side menu, click on "Configure".

Step 2: Navigate to the "Build Triggers" Section

  1. Scroll down the configuration page until you find the "Build Triggers" section.

Step 3: Enable "Build periodically"

  1. Check the box next to "Build periodically". This will reveal a text area labeled "Schedule".

Step 4: Define the Schedule using Cron Syntax

The "Schedule" field uses cron syntax, a standard way to define time-based jobs in Unix-like systems. Don't let it intimidate you; we'll break it down. A cron expression has five fields, separated by spaces:

MINUTE HOUR DAY MONTH DAY_OF_WEEK

Here's what each field represents:

  • MINUTE: 0-59

  • HOUR: 0-23

  • DAY: 1-31

  • MONTH: 1-12 or JAN-DEC (case-insensitive)

  • DAY_OF_WEEK: 0-7 or SUN-SAT (0 and 7 both represent Sunday)

You can use specific values, ranges (e.g., 1-5), lists (e.g., 0,30), or wildcards (* for all values) in each field.

Examples:

  • Run every hour at minute 0: 0 * * * *

  • Run every day at 3:00 AM: 0 3 * * *

  • Run every Monday at 6:00 PM: 0 18 * * 1 (Here, 1 represents Monday)

  • Run every 30 minutes: */30 * * * * (The */ syntax means "every")

For our "Hello World!" example, let's schedule it to run every 5 minutes for demonstration purposes:

  1. In the "Schedule" text area, enter:

     H/5 * * * *
    

    Understanding H/5 * * * *:

    • H: This is a special symbol that instructs Jenkins to pick a pseudo-random minute (between 0 and 59) to start the periodic execution. This helps in distributing the load if you have many periodically triggered jobs.

    • /5: When combined with H, it means "every 5 minutes, starting at some point within the hour."

    • * * * *: These wildcards mean "every hour," "every day of the month," "every month," and "every day of the week," respectively.

Step 5: Save the Configuration

  1. Scroll down to the bottom of the configuration page and click "Save".

Observing the Periodic Builds

Now that you've configured the periodic trigger, Jenkins will automatically run your HelloWorldPeriodic job every 5 minutes. You can observe this in the "Build History" section on the left-hand side of the job's overview page. You should see new builds being initiated automatically at approximately 5-minute intervals.

Click on any of the build numbers to view the "Console Output" and confirm that your "Hello World!" message is being printed as expected.

Why Periodic Builds are Useful

Periodic builds are a fundamental building block in automation. They are useful for various tasks, such as:

  • Scheduled Backups: Running backup scripts at regular intervals (e.g., nightly).

  • Health Checks: Periodically checking the status of applications or servers.

  • Data Synchronization: Regularly syncing data between different systems.

  • Nightly Builds: Compiling and testing code every night.

By mastering the "Build periodically" trigger in Jenkins, you've taken another significant step towards automating your workflows and embracing the power of DevOps. Keep experimenting with different cron expressions to schedule your jobs according to your specific needs.

0
Subscribe to my newsletter

Read articles from Divakar Chakali directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Divakar Chakali
Divakar Chakali

I'm a DevOps enthusiast and software engineer with 3.5 years of hands-on experience building scalable CI/CD pipelines, automating infrastructure, and streamlining deployment workflows. I specialize in tools like Jenkins, Maven, Docker, and Tomcat, and I love turning complex systems into elegant, maintainable solutions. On Hashnode, I share insights, tutorials, and real-world lessons from the trenches—whether it's debugging flaky builds, optimizing deployment strategies, or exploring the latest in cloud-native tech. My goal is to help developers and ops teams collaborate better, ship faster, and learn continuously.