Automate "Hello World!" with Jenkins Freestyle: Your First Step to DevOps Mastery

Divakar ChakaliDivakar Chakali
5 min read

Namaste Folks! 🙏 It's your favourite DevOps aficionado back with another insightful piece. With half a million of you keen learners tuning in, we're constantly exploring the practical side of DevOps. Today, we're taking it back to the basics with a fundamental yet crucial concept in Jenkins: the Freestyle Job.

For those just starting their automation journey, or even seasoned pros looking to quickly automate a simple task, the Freestyle Job in Jenkins is your trusty friend. We'll walk through creating a straightforward job that does just one thing: displays the timeless "Hello World!" message upon a successful build. Think of this as your "Hello World!" moment with Jenkins automation!

Understanding the Versatile Freestyle Job

Before we dive into the example, let's quickly recap what makes the Freestyle Job so versatile. In essence, it's a highly flexible project type within Jenkins that allows you to define a sequence of build steps through a user-friendly graphical interface. Unlike more opinionated project types like Pipelines or Multibranch Pipelines (which we'll delve into in future articles, don't worry!), Freestyle gives you granular control over each stage of your automation process.

This flexibility makes it perfect for:

  • Automating simple scripts and commands.

  • Integrating various tools and technologies.

  • Quickly setting up basic automation workflows.

  • Serving as a stepping stone to understanding more complex Jenkins features.

Creating Our "Hello World!" Freestyle Job: A Step-by-Step Guide

Alright, let's get our hands dirty and create this simple yet foundational job. Make sure you have a running Jenkins instance. If you're new to Jenkins, there are plenty of excellent resources online to help you get started.

Step 1: Creating a New Item

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

  2. Enter a name for your job, something descriptive like "HelloWorldJob".

  3. Select the "Freestyle project" option.

  4. Click "OK".

Step 2: Configuring the General Settings (Optional but Recommended)

You'll now be on the configuration page for your newly created job.

  1. In the "Description" field, add a brief explanation like: "This is a simple Freestyle Job that prints 'Hello World!' to the console." This helps in understanding the purpose of the job later.

  2. Feel free to explore other options like "Discard old builds" to manage your Jenkins disk space, but for this simple example, we can leave the defaults.

Step 3: Skipping Source Code Management and Build Triggers

For this particular job, we don't need to pull any source code, nor do we need a specific trigger. We'll manually build this job. So, you can leave the "Source Code Management" and "Build Triggers" sections as they are (the default "None" and no triggers selected).

Step 4: Defining the "Hello World!" Build Step

This is where the magic happens! We'll add a simple build step to execute a command that prints our message.

  1. Scroll down to the "Build" section.

  2. Click on the "Add build step" dropdown menu.

  3. Select "Execute shell" (if your Jenkins agent is running on a Unix-like system) or "Execute Windows batch command" (if your agent is on Windows). Since we're a global audience, let's provide both.

    • For "Execute shell" (Linux/macOS): In the "Command" text area, enter:
echo "Hello World!"
  • For "Execute Windows batch command": In the "Command" text area, enter:
echo Hello World!

Explanation: The echo command (or echo in batch) is a standard command-line utility that simply prints the text following it to the console output.

Step 5: Skipping Post-build Actions

For this very basic job, we don't need any actions to be performed after the build. You can leave the "Post-build Actions" section empty.

Step 6: Saving Your Job

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

Running Your First "Hello World!" Build

Congratulations! You've configured your first Jenkins Freestyle Job. Now, let's run it:

  1. On your Jenkins dashboard, you should see your "HelloWorldJob".

  2. Hover over the job name, and you'll see a few icons. Click on the "Build Now" icon (it looks like a play button).

  3. Jenkins will immediately schedule and execute your build. You'll see a new entry appear under the "Build History" on the left-hand side.

  4. Click on the build number (e.g., #1) to view the build details.

  5. On the build details page, click on "Console Output".

You should see something like this in the console output:

For "Execute shell":

Started by user Divakar Chakali
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/HelloWorldJob
[HelloWorldJob] $ /bin/sh -xe /tmp/jenkins2128916742062939626.sh
+ echo Hello World!
Hello World!
Finished: SUCCESS

For "Execute shell": For "Execute Windows batch command":

Started by user Divakar Chakali
Running as SYSTEM
Building in workspace C:\Users\nani\.jenkins\workspace\HelloWorldJob
[HelloWorldJob] $ cmd /c call C:\Users\nani\AppData\Local\Temp\jenkins1447607847134190341.bat

C:\Users\nani\.jenkins\workspace\HelloWorldJob>echo Hello World! 
Hello World!

C:\Users\nani\.jenkins\workspace\HelloWorldJob>exit 0 
Finished: SUCCESS

Notice the line Hello World! printed in the console output, usually under a section related to the "Execute shell" or "Execute Windows batch command" build step. Your first Jenkins automation task is a success!

Taking Your First Steps Further

While this "Hello World!" example is incredibly simple, it lays the foundation for understanding how Jenkins Freestyle Jobs work. You can now start experimenting with adding more complex build steps, integrating with version control systems, setting up build triggers, and defining post-build actions.

The beauty of Jenkins lies in its extensibility through a vast ecosystem of plugins. As you progress, you'll discover plugins that allow you to interact with various tools in your DevOps pipeline, from building and testing frameworks to deployment tools and monitoring systems.

Stay tuned for future articles where we'll delve deeper into more advanced Jenkins concepts like Pipelines and Multibranch Pipelines. Keep learning, keep automating, and remember: every complex automation journey begins with a simple "Hello World!"

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.