Operations 10 min read

Master Jenkins Pipeline: A Step‑by‑Step Guide to Build, Script, and Run CI/CD Pipelines

This tutorial walks you through creating a Jenkins Pipeline job, writing the Groovy‑based script, defining agents, stages, and steps, configuring parameters, running the pipeline, and viewing detailed build output, providing a complete hands‑on guide for CI/CD automation.

FunTester
FunTester
FunTester
Master Jenkins Pipeline: A Step‑by‑Step Guide to Build, Script, and Run CI/CD Pipelines

Part 01 – Create a Pipeline Job

In Jenkins, create a new job of type Pipeline . Log in, click “New Item”, select “Pipeline”, and give the job a name.

Configure the job by specifying the pipeline definition (e.g., “Pipeline script”) and optionally adding parameters.

Part 02 – Write the Pipeline Script

Select the “Pipeline script” tab and enter a Groovy‑based script that describes the entire delivery process.

The script consists of several blocks:

pipeline – root block.

agent – defines where the pipeline runs.

stages – a collection of stage blocks.

steps – individual commands inside a stage.

Example of a basic pipeline

pipeline {
    agent any
    stages {
        stage('Build') {
            steps { sh 'mvn clean package' }
        }
        stage('Test') {
            steps { sh 'mvn test' }
        }
        stage('Deploy') {
            steps { sh 'deploy.sh' }
        }
    }
}

Part 03 – Define Stages

Each stage represents a distinct phase such as build, test, or deploy. Inside a stage you place a steps block.

stage('Stage Name') {
    steps {
        // Steps to be executed in this stage
    }
}

Part 04 – Configure Agent

The agent block selects the node on which the pipeline runs. You can use the default any node, a specific label, or a Docker container.

agent {
    docker {
        image 'dockerimage'
        args '--name myname'
    }
}

Part 05 – Add Steps

Steps perform concrete tasks such as pulling code, compiling, testing, or deploying. They can be shell commands or calls to external scripts.

steps {
    sh 'mvn clean package'   // Build
    sh 'mvn test'            // Test
    sh 'deploy.sh'            // Deploy
}

Part 06 – Run the Pipeline

Save the job and click “Build Now”. Jenkins will execute the defined stages in order, displaying real‑time logs.

Typical workflow:

Open Jenkins UI, create a new Pipeline project.

Enter project name and description, save.

Select “Pipeline script from SCM” to pull the script from a repository (e.g., GitHub).

Choose the pipeline language (Groovy, Python, or Shell).

Test the script via console output or logs.

Save and trigger a build.

Monitor each step’s output and status in the console.

After completion, review build results and logs.

Part 08 – View Pipeline Output

In the Jenkins UI you can inspect build history and detailed logs for each stage and step, including duration and error messages. The CLI also provides commands such as jb jobs -w to list builds and jb job# -b to show details. Additionally, the Blue Ocean plugin offers a visual overview of pipeline execution.

By following these steps, you can create reproducible, readable, and manageable CI/CD pipelines with Jenkins, improving delivery quality and efficiency.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdAutomationDevOpsPipelineJenkins
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.