Introducing IaCConf 2025, the free virtual event for elevating your IaC skills

➡️ Register Now

General

Jenkins Tutorial for Beginners: Step-by-Step Pipeline

jenkins tutorial

🚀 Level Up Your Infrastructure Skills

You focus on building. We’ll keep you updated. Get curated infrastructure insights that help you make smarter decisions.

In this Jenkins tutorial, we will explore Jenkins and how it enables CI/CD automation for software development. We will walk through its core features and benefits and learn how to set up a fully functional Jenkins CI/CD pipeline. We will cover the following topics:

  • Key benefits and features of Jenkins
  • Installing Jenkins on Windows
  • Accessing the Jenkins dashboard
  • Creating a simple Jenkins pipeline
  • Writing and executing a basic pipeline script

By the end, you will gain hands-on experience building a Jenkins pipeline and streamlining development workflows.

What is Jenkins?

Jenkins is an open-source automation server that helps developers implement continuous integration and continuous deployment (CI/CD) workflows. It simplifies software development by automating build, test, and deployment tasks. 

Jenkins reduces manual effort by automating the execution of different development workflows. It operates using highly customizable pipelines that can be configured using Groovy-based scripts. 

Developers can commit code changes to Git repositories, and Jenkins then detects these updates to initiate the build process automatically. The build process in Jenkins includes compiling source code and running tests to provide feedback. 

Jenkins also supports continuous delivery by managing dependencies and deploying artifacts like JAR files or container images. Its extensive plugin ecosystem allows teams to customize workflows for version control, testing, deployment, and reporting.

At its core, Jenkins uses jobs (or pipelines) to define automation processes like building, testing, and deploying code. These jobs can be configured manually or scripted using Jenkins Pipeline DSL, which allows version-controlled, code-based automation.

A Jenkins environment consists of the master server (controller) and its connected agents, which run the defined jobs. Jenkins also relies heavily on a plugin-based architecture, enabling integration with countless tools and systems in the DevOps ecosystem.

Key features of Jenkins

Jenkins provides a flexible automation platform designed to streamline CI/CD workflows. Its powerful features make it a great choice for software teams

  • Pipeline as code:  Jenkins allows developers to define CI/CD workflows using code for better control and repeatability.
  • Extensive plugin support:  Thousands of plugins help extend functionality for testing, deployments, and integrations.
  • Distributed build system: Jenkins can run builds across multiple machines to speed up execution and handle large projects.
  • Version control integration: Jenkins integrates with Git, SVN, and other version control systems to track changes.
  • Customizable build triggers: Developers can set up automated builds based on code commits, schedules, or external events.
  • Security and access control: Role-based access ensures secure management of builds and sensitive project configurations.
  • Cloud and container support: Jenkins works with cloud services and container platforms like AWS, Kubernetes, and Docker
  • Built-in monitoring and reporting: Jenkins provides real-time logs, build reports, and test results for better project visibility.

Benefits of Jenkins

Jenkins can help automate the entire software build, test, and deployment process, which improves development efficiency and reduces the risk of human error. Here are the main benefits of using Jenkins:

  • Free and open source: Jenkins offers a cost-effective alternative to proprietary CI/CD tools. It is backed by an active developer community that continually contributes plugins and updates.
  • Accelerated development pipelines: Jenkins automates tasks like code compilation, testing, and deployment, reducing manual handoffs and significantly shortening release cycles.
  • Proactive issue detection: Continuous integration enables early identification of regressions or integration conflicts, lowering the likelihood of production defects.
  • Enforced quality gates: Built-in support for automated testing and static code analysis ensures that only code meeting defined quality thresholds proceeds to production.
  • Horizontal scaling: Jenkins’ master-agent architecture allows teams to manage parallel builds across distributed systems, making it suitable for projects of increasing complexity and scale.
  • Customizable workflows: Jenkins supports fine-grained control over build pipelines through tools like Jenkins Pipeline and Declarative DSL, enabling teams to tailor automation to project-specific logic.
  • Centralized monitoring and reporting: Jenkins provides real-time feedback through build dashboards, test summaries, and integration with issue tracking tools, improving visibility and coordination across teams.

How to create a Jenkins pipeline

Below is an example of a simple Jenkins pipeline, which will automate the build, test, and deployment process for a sample project. 

The pipeline checks that every change made to the codebase is tested and deployed efficiently. With Jenkins, pipelines provide a way to define these steps as code to maintain and repeat across different projects.

Step 1: Install Jenkins

Jenkins offers a user-friendly Windows installer that simplifies the setup process by installing Jenkins as a Windows service. This ensures that Jenkins runs efficiently in the background with minimal manual configuration. The installer also integrates with system services to automate software builds and deployments easily.

Jenkins also provides platform-specific installation support for users installing Jenkins on other platforms, such as Linux, macOS, Kubernetes, or Docker. 

Additionally, Jenkins can be run using the standalone WAR file to achieve greater flexibility in deployment. Check out the official Jenkins documentation to explore the detailed installation guide based on your preferred operating system or environment.

Prerequisites

Before installing Jenkins on Windows, your system must have at least 256 MB of RAM and 1 GB of storage. If you plan to use Jenkins for Docker setups, you need a minimum of 10 GB of storage. A setup with 4GB+ of RAM and 50GB+ of storage is ideal for small teams.

Jenkins also requires a compatible Java version. For more details, refer to the Java Requirements page. For smooth installation, Jenkins installation requires a compatible web browser with Jenkins UI and adherence to the Windows Support Policy.

1. Download the Jenkins installer

To begin the Jenkins installation, visit the Jenkins Download page. There, you can choose between an LTS release and a weekly release for Windows. 

After selecting the appropriate version, click the “Windows” option to download the installer package. Once the download is complete, run the installer to begin the installation process.

2. Initiate the setup wizard

Once you click Next, it directs you to specify the destination folder path.

3. Configure installation directory and user settings

Choose the directory where Jenkins should be installed and click Next to specify a local or domain user for running Jenkins. Click Test Credentials to validate permissions, and click Next after successful validation.

4. Port selection

Choose the port Jenkins should listen on (default: 8080), click the Test Port option to ensure it is free, and choose Next to proceed.

5.  Java home directory

The installer detects your Java installation automatically. If Java is missing, install it and specify the Java home directory. Click Next to continue.

6. Install Jenkins

Click Install to start the installation and wait for the installation to complete.

Click Finish when complete.

7. Post-installation validation

Open Windows Services and check if Jenkins is running to verify the installation. Otherwise, you can navigate to http://localhost:8080 in your browser for verification.

jenkins Post-installation validation

Once you retrieve the initialAdminPassword from C:/Program Files/Jenkinssecrets and enter it on the Unlock Jenkins page, you can customize Jenkins with Plugins. 

You can click Install Suggested Plugins for a basic setup.

install jenkins plugins

Now, create the First Administrator User by providing a username, password, and a valid email for the admin account. Click Save and Continue.

Jenkins installation is complete.

Step 2: Log in with admin credentials

After you log in to Jenkins, you can explore the Dashboard options.

The Jenkins dashboard provides essential features like:

  • Build History for tracking past builds
  • Manage Jenkins for configuring system settings
  • Build Queue to monitor pending builds

You can create and manage Jenkins jobs to automate your software processes and set up distributed builds for scalability. The dashboard has options to configure agents and enhance build performance. 

The Build Executor Status shows the availability of resources for running builds, allowing you to manage workloads efficiently. With these options, you can streamline and optimize your continuous integration workflow.

Step 3: Create a new item (Pipeline)

From the Jenkins Dashboard, click on the + New Item option to open the form below.

create jenkins new item

Here, you have different options to select (Freestyle project, pipeline, multi-configuration project, and more). Since we will build a pipeline, select “pipeline” as the item type and give it a suitable name, e.g., “My Basic Pipeline.” 

Click on OK to proceed with the pipeline configurations.

Step 4: Set the general pipeline configuration options

The Configure page for a Jenkins pipeline provides several configuration options. Under General, you can add a description, discard old builds, and control concurrent builds or allow the pipeline to resume after a controller restart. 

general pipeline configuration options

You can also link a GitHub project and set pipeline speed/durability or preserve build stashes. The Build Triggers section allows you to trigger builds based on other project builds, schedule periodic builds, use GitHub hooks, or poll the SCM for changes. 

In the Pipeline section, you can define the pipeline directly using Groovy scripts or fetch it from source control. You can also enable the Groovy sandbox for added security and resiliency.

Step 5: Define the pipeline

At this stage, the advanced project options don’t have much to configure, so we can skip them for now and focus on the core pipeline setup. 

You will see two options in the Definition field:

  1. Pipeline Script
  2. Pipeline Script from SCM
Define the jenkins pipeline

Selecting the Pipeline script” allows you to write the declarative pipeline code directly in the provided text box. This script defines the steps Jenkins will execute, such as building, testing, and deploying your software. 

For most beginners, using the pipeline block is the simplest and quickest way to start with Jenkins pipelines.

Alternatively, you can choose the Pipeline script from SCM option to store and manage the pipeline script in a source control management (SCM) system like Git. The scripted pipeline approach benefits teams that need version control and collaboration on the pipeline script. 

However, for this example, we’ll stick with the Pipeline script option to keep things straightforward and focus on directly defining a simple pipeline script in the Jenkins UI.

Step 6: Script the pipeline

Jenkins pipelines are defined using Groovy script, which is a flexible language for defining build steps and stages. The script allows developers to describe build, test, and deployment tasks as code. Jenkins executes such scripts automatically to streamline different CI/CD workflows.

The code below represents a basic pipeline structure that starts with the declaration. The “agent any” line tells Jenkins to execute the pipeline on any available agent or node. This is the most basic setup for picking any available executor for the job.

The agent defines where the pipeline will run, ensuring the execution environment is set.

pipeline {
    agent any
}

The updated script introduces the stages section to organize the pipeline into different steps. Each stage defines a logical unit of work, such as building, testing, or deploying. 

The stages block helps structure the pipeline, making it easy to follow and troubleshoot. You can define multiple stages, each with its own actions to execute.

pipeline {
    agent any
    
    stages {
          // define stages here
    }
}

The post section handles actions after the pipeline completes, whether it succeeds or fails. In this section, you can define custom actions based on the pipeline’s outcome. 

The success block runs after a successful execution, while the failure block runs if the pipeline fails. This section is essential for managing results and taking appropriate actions after the pipeline runs.

pipeline {
    agent any
    
    stages {
     	// define stages here   
     }
    
    post {
        success {
            // define next action after success
        }
        failure {
            // define next action after failure
        }
    }
}

In the complete example, the stages block defines specific stages like ‘Build,’ ‘Test,’ and ‘Deploy.’ Each stage contains steps that describe actions like printing messages or running shell commands. 

The post section provides feedback on the pipeline’s result, with custom messages for success or failure. 

This example demonstrates how Jenkins automates tasks, providing clear feedback on execution outcomes.

pipeline {
    agent any
    
    stages {
        stage('Build') {
            steps {
                echo 'Building the project...'
	         // bash/shell commands
            }
        }
        
        stage('Test') {
            steps {
                echo 'Running tests...'
	         // bash/shell commands
            }
        }
        
        stage('Deploy') {
            steps {
                echo 'Deploying the application...'
	         // bash/shell commands
            }
        }
    }
    
    post {
        success {
            echo 'Pipeline executed successfully!'
        }
        failure {
            echo 'Pipeline failed. Please check the logs for details.'
        }
    }
}

To save this script in Jenkins, click the “Save” button at the bottom of the configuration page. Once saved, Jenkins will use the script for the pipeline whenever the job is triggered. 

You can always come back to edit the script as needed. Make sure to save your progress to ensure the pipeline runs as expected.

jenkins pipeline script

Step 7: Save the pipeline

After saving the pipeline, visit the main dashboard of the configured pipeline to see its status. You can access this by clicking on the job name from the Jenkins home page. 

Here, you’ll find options like ‘Build Now,’ ‘Configure,’ and ‘Delete Project.’ These options allow you to trigger builds, adjust settings, and manage your pipeline.

jenkins stage view

Step 8: Run the pipeline

To run the pipeline, click the “Build Now” button on the dashboard page. This will trigger the pipeline’s execution according to the defined script. You can monitor the build’s progress in real time and review past executions. 

The “Builds” block lists current and past builds, allowing you to revisit previous runs and inspect their outcomes.

jenkins basic pipeline view

As shown above, post actions are executed successfully when the pipeline finishes and both success and failure logs are printed.

jenkins stage logs successful
jenkins stage logs failed

After the pipeline executes, the post actions configured earlier will run based on the outcome. If the pipeline succeeds, the success block prints the success message, and if it fails, the failure block prints the failure message. 

These logs give you insight into what happened during the execution. Clicking on the specific build blocks in the ‘Build History’ lets you view the results in detail.

Step 9: Access the logs

To view detailed logs for each pipeline run, click on a specific build number under the “Build History” section. This opens the build’s log, showing every executed action and command. Logs provide crucial feedback for debugging and optimizing the pipeline. 

You can see whether each step in the pipeline succeeded or failed, and the exact output for each step.

jenkins console output

Here are the available pipeline management options:

  • Status – View the current status of the pipeline execution.
  • Changes – Check recent changes that triggered the pipeline.
  • Console Output – View detailed logs of the pipeline execution.
  • View as Plain Text – See the console output in plain text format.
  • Edit Build Information – Modify details about the current pipeline run.
  • Delete build ‘#2’ – Remove the current build from Jenkins.
  • Restart from Stage – Re-run the pipeline from a specific stage.
  • Replay – Re-execute the pipeline without modifying the script.
  • Pipeline Steps – Inspect and analyze the execution steps of the pipeline.
  • Workspaces – Access the workspace directory used by the pipeline.
  • Previous Build – Navigate to the previous build and review the details.

These pipeline management options provide complete control over pipeline execution. You can efficiently manage, track, and troubleshoot your pipeline using these options to ensure smooth and continuous integration.

Alternative to Jenkins - Spacelift

When it comes to infrastructure orchestration, generic CI/CD platforms such as Jenkins or CircleCI are not specialized enough to manage everything you might need in your workflows. That’s where Spacelift shines.

Spacelift is an IaC management platform that helps you implement DevOps best practices. It provides a dependable CI/CD layer for infrastructure tools including OpenTofu, Terraform, Pulumi, Kubernetes, Ansible, and more, letting you automate your IaC delivery workflows.

DevOps accelerator Cloud Posse had invested two years of effort trying to adopt tools like Atlantis, Jenkins, and Terraform Cloud, but those tools came nowhere near delivering what was needed. Then, a customer suggested they take a look at a new addition to the IaC CI/CD tools market that had caught their attention — Spacelift. Now, every customer IaC implementation they complete includes Spacelift as a key part of the final DevOps IaC environment they set up.

Spacelift customer case study

Read the full story

Spacelift is designed for your whole team. Everyone works in the same space, supported by robust policies that enforce access controls, security guardrails, and compliance standards. This means you can manage your DevOps infrastructure far more efficiently without compromising on safety.

Let’s see how Spacelift avoids the limitations of generic CI/CD tools:

  • Policies to control what kind of resources engineers can create, what parameters they can have, how many approvals you need for a run, what kind of task you execute, what happens when a pull request is open, and where to send your notifications
  • Stack dependencies to build multi-infrastructure automation workflows with dependencies, having the ability to build a workflow that, for example, generates your EC2 instances using Terraform and combines it with Ansible to configure them
  • Self-service infrastructure via Blueprints, or Spacelift’s Kubernetes operator, enabling your developers to do what matters – developing application code while not sacrificing control
  • Creature comforts such as contexts (reusable containers for your environment variables, files, and hooks), and the ability to run arbitrary code
  • Drift detection and optional remediation

To learn more about Spacelift, create a free account today or book a demo with one of our engineers.

Key points

We covered Jenkins’s core features and benefits and explored how it enables CI/CD workflow automation. We also explored its diverse plugin ecosystem, distributed build system, and cloud support flexibility. 

We learned how to install Jenkins on Windows and access the dashboard via a web browser. Jenkins provides easy configuration options for creating and managing pipelines for continuous delivery and integration.

We also guided you through configuring a simple pipeline script and detailed actions for success and failure. You learned how to manage Jenkins builds, trigger tasks, and monitor pipeline execution. 

This Jenkins tutorial provided a hands-on approach to building pipelines, configuring stages, and accessing logs. With this foundational knowledge, you can automate your workflows and streamline your development process with Jenkins.

Solve your infrastructure challenges

Spacelift is an alternative to using homegrown solutions on top of a generic CI. It helps overcome common state management issues and adds several must-have capabilities for infrastructure management.

Learn more

Thu, May 15, 2025 @ 11:00am EDT

The First Community-Driven
IaC Conference

Register now