Certified Jenkins Engineer

Jenkins Pipelines

Demo Simple Pipeline Job

In this guide, you’ll learn how to set up a basic Jenkins Pipeline that prints “Hello World” and then extends to run Maven commands. We’ll cover:

  • Creating a Pipeline project
  • Configuring the pipeline script
  • Running a Hello World job
  • Viewing build output and timing
  • Adding automatic Maven installation

Whether you’re new to Jenkins or looking for a refresher, this step-by-step tutorial will get you up and running quickly.

1. Create a Pipeline Project

  1. In the Jenkins UI, click New Item.
  2. Enter hello-world-pipeline as the name.
  3. Select Pipeline and click OK.

You now have a fresh Pipeline project ready to configure.

The image shows a Jenkins interface where a new item named "hello-world-pipeline" is being created, with the "Pipeline" option selected.

2. Configure the Pipeline

Open your new project’s configuration to see sections like General, Build Triggers, and Pipeline. You can:

OptionDescription
DescriptionAdd context about the job’s purpose.
Build TriggersSchedule with cron or poll SCM.
Pipeline scriptPaste your Declarative Pipeline directly in Jenkins.
Pipeline script from SCMStore your Jenkinsfile in a repository for version control.
  1. Under Pipeline, choose Pipeline script.
  2. (Optional) Enable Use Groovy Sandbox to restrict script permissions.

The image shows a configuration screen for a "hello-world-pipeline" in a web interface, where a pipeline script can be defined and edited. There are options to use a Groovy Sandbox and buttons to save or apply changes. The image shows a Jenkins configuration screen for a pipeline project, with options for defining the pipeline script from SCM, selecting SCM type, and specifying the script path.

3. Hello World Pipeline

Paste this Declarative Pipeline into the script box:

pipeline {
    agent any
    stages {
        stage('Hello') {
            steps {
                echo 'Hello World'
            }
        }
    }
}
  • agent any runs on any available node.
  • stage('Hello') contains an echo 'Hello World' step.

Note

Enabling the Groovy Sandbox is recommended if you’re running untrusted scripts. It prevents unauthorized method calls.

Click Apply, Save, then Build Now.

4. View the Results

After triggering the job, the dashboard shows build status, history, and links to console output.

The image shows a Jenkins dashboard for a pipeline named "hello-world-pipeline," displaying its status, build history, and permalinks for recent builds.

Click the build number or stage name to open the console log:

The image shows a Jenkins pipeline console with a successful build labeled "Build #1," displaying details of the "Hello" stage and a "Hello World" print message.

Raw console output:

Started by user admin
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/hello-world-pipeline
[Pipeline] {
[Pipeline]   stage (Hello)
[Pipeline]   { (Hello)
[Pipeline]     echo
Hello World
[Pipeline]   } // stage
[Pipeline] } // node
[Pipeline] End of Pipeline
Finished: SUCCESS

Switch to Pipeline Steps or Timing to see per-step durations:

The image shows a Jenkins dashboard displaying the status of a build process, including details like build duration and timing. The interface includes options for viewing console output, editing build information, and pipeline overview. The image shows a Jenkins interface displaying the steps of a pipeline execution, including stages and their execution times. The pipeline steps are listed with their respective arguments and status indicators.

5. Extending with Maven

Let’s enhance the pipeline to print the Maven version. Add a tools block:

pipeline {
    agent any
    tools {
        // Install the Maven version configured as "M3"
        maven "M3"
    }
    stages {
        stage('Echo Version') {
            steps {
                sh 'echo Print Maven Version'
                sh 'mvn -version'
            }
        }
    }
}

Warning

If you run this now, you’ll get a compilation error because the tool name M3 isn’t defined in Jenkins yet.

WorkflowScript: 6: Tool type "maven" does not have an install of "M3" configured - did you mean "null"? @ line 6, column 15.
    maven "M3"
             ^
1 error
Finished: FAILURE

6. Configure Maven in Jenkins

  1. Navigate to Manage Jenkins > Global Tool Configuration.
  2. Under Maven installations, click Add Maven.
  3. Name it M398, enable Install automatically, and choose version 3.9.8.
  4. Save your changes.

The image shows the "Manage Jenkins" dashboard interface, displaying various configuration and security options for managing Jenkins settings. It includes sections for system configuration, tools, plugins, and security settings. The image shows a Jenkins configuration page for managing Maven installations, with options to install specific versions automatically.

Now update your Pipeline to use M398:

pipeline {
    agent any
    tools {
        maven "M398"
    }
    stages {
        stage('Echo Version') {
            steps {
                sh 'echo Print Maven Version'
                sh 'mvn -version'
            }
        }
    }
}

7. Build and Verify

Click Build Now again. You’ll see Tool Installation followed by Echo Version.

Console snippet:

+ echo Print Maven Version
Print Maven Version
+ mvn -version
Apache Maven 3.9.8 (36645f6c9b57998e5a5009217e36f2cff343256)
Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/M398
Java version: 17.0.12, vendor: Ubuntu, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.8.0-39-generic", arch: "amd64", family: "unix"
Finished: SUCCESS

Conclusion

You’ve now:

  • Created a Jenkins Pipeline project
  • Written and executed a “Hello World” pipeline
  • Viewed build logs and timing
  • Configured Jenkins to install Maven automatically

Next steps: integrate SCM checkout, add test and deploy stages, and configure post-build notifications.

Watch Video

Watch video content

Previous
Additional Pipeline Configuration