Certified Jenkins Engineer

Jenkins Pipelines

Demo Create Pipeline using Blue Ocean Graphical Editor

In this guide, you’ll learn how to install the Blue Ocean plugin in Jenkins, create and configure a multibranch pipeline with its graphical editor, archive build artifacts, publish JUnit reports, and view results both in Blue Ocean and the classic UI. Each step includes screenshots to illustrate the workflow.


1. Install the Blue Ocean Plugin

  1. Navigate to Manage Jenkins → Plugin Manager → Available.
  2. Search for blueocean, select the plugin bundle, and click Install without restart.

Note

Blue Ocean requires Jenkins 2.x and the Pipeline plugin. Ensure your instance meets these prerequisites before installation.

The image shows a Jenkins plugin management interface with a search for "blueocean," displaying several plugins related to Blue Ocean, including one marked as deprecated.

After installation, return to the dashboard. You should see Open Blue Ocean in the sidebar.

The image shows a Jenkins dashboard displaying the download progress of plugins, with successful connectivity checks and plugin installations.

The image shows a Jenkins dashboard displaying a list of jobs with their status, last success, last failure, and duration. The sidebar includes options like "Build History" and "Open Blue Ocean."


2. Launch Blue Ocean and Create a New Pipeline

  1. Click Open Blue Ocean → New Pipeline.
  2. Select Git, enter your repository URL, and add credentials if needed.
  3. Blue Ocean will scan branches for a Jenkinsfile and automatically trigger the pipeline if found.

The image shows a Jenkins interface for creating a pipeline, where a user is connecting to a Git repository by entering a repository URL and selecting user credentials.

Once branches are indexed and a run starts, you’ll see the activity feed:

The image shows a Jenkins dashboard displaying a pipeline activity for a project named "jenkins-hello-world." It includes details such as the status, run number, commit ID, branch, message, and duration of the activity.


3. Example Jenkinsfile and Stage Overview

Below is the sample Jenkinsfile stored in your repository. It defines three key stages:

pipeline {
  agent any
  tools { maven 'M398' }
  stages {
    stage('Echo Version') {
      steps {
        sh 'echo Print Maven Version'
        sh 'mvn -version'
      }
    }
    stage('Build') {
      steps {
        sh 'mvn clean package -DskipTests=true'
      }
    }
    stage('Unit Test') {
      steps {
        script {
          for (int i = 0; i < 60; i++) {
            echo "${i + 1}"
            sleep 1
          }
        }
        sh 'mvn test'
      }
    }
  }
}
Stage NamePurposeCommands
Echo VersionDisplay Maven environment detailsmvn -version
BuildCompile and package the appmvn clean package -DskipTests=true
Unit TestExecute unit testsmvn test (with optional sleep loop)

After triggering the pipeline, you can monitor each stage in real time:

The image shows a Jenkins pipeline interface with a progress bar indicating stages from "Start" to "End," currently at the "Unit Test" stage. Below, there are details of unit test steps, all marked as successful.


Viewing Console Logs

Echo Version stage output:

mvn -version
Apache Maven 3.9.8 (3645f66c…)
Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven.MavenInstallation/M398
Java version: 17.0.7, vendor: Ubuntu
OS name: "linux", version: "6.8.0-39-generic"

Build stage output:

mvn clean package -DskipTests=true
[INFO] Scanning for projects…
[INFO] Building hello-demo 0.0.1-SNAPSHOT
[INFO] --- maven-clean-plugin:3.3.2:clean (default-clean) @ hello-demo ---
…

The image shows a Jenkins pipeline interface with a completed unit test stage, displaying a series of steps and their execution times. The pipeline stages are visually represented with checkmarks indicating successful completion.


4. Inspect the Multibranch Pipeline Configuration

Blue Ocean automatically creates a Multibranch Pipeline job in the classic UI:

The image shows a Jenkins configuration page for a project named "jenkins-hello-world," with options for setting branch sources and other configurations. The interface includes fields for display name, description, and Git project repository URL.

When Jenkins scans your repository, it runs:

> git ls-remote -h -- http://…/jenkins-hello-world.git
Checking branch main
'Jenkinsfile' found
Met criteria
Scheduled build for branch: main
Processed 1 branches
Finished: SUCCESS

5. Edit the Pipeline in Blue Ocean

Back in Blue Ocean:

  1. Select your branch and click the pencil icon to open the visual editor.
  2. Remove the sleep loop in Unit Test to simplify:
stage('Unit Test') {
  steps {
    sh 'mvn test'
  }
}

Press Ctrl+S (or Command+S on Mac) to save and commit the changes to your Jenkinsfile.


6. Archive Build Artifacts

  1. In the Build stage, click + Add Step → Archive Artifacts.
  2. Enter the file pattern: target/hello-demo-*.jar.

Verify on the Jenkins controller:

cd /var/lib/jenkins/workspace/jenkins-hello-world_main/target
ls
hello-demo-0.0.1-SNAPSHOT.jar

Your updated Build stage:

stage('Build') {
  steps {
    sh 'mvn clean package -DskipTests=true'
    archiveArtifacts 'target/hello-demo-*.jar'
  }
}

7. Publish JUnit Test Results

The JUnit plugin is pre-installed, as shown here:

The image shows a Jenkins interface with the "Installed plugins" section open, displaying the JUnit Plugin, which allows JUnit-format test results to be published.

To add JUnit reporting:

  1. Edit the Unit Test stage → + Add Step → Archive JUnit-formatted test results.
  2. Enter target/surefire-reports/TEST-*.xml and select Keep properties and Keep test names.

Final Unit Test stage snippet:

stage('Unit Test') {
  steps {
    sh 'mvn test'
    junit testResults: 'target/surefire-reports/TEST-*.xml', keepProperties: true, keepTestNames: true
  }
}

8. Commit and Validate Changes

Click Save, add a commit message (e.g., “Archive artifacts and publish JUnit reports”), and push to the main branch:

The image shows a Jenkins interface with a "Save Pipeline" dialog box open, allowing the user to commit changes to a Jenkinsfile in a repository. The dialog includes options to commit to the main branch or a new branch, with a description field filled in.

Warning

If you mistype the artifact pattern (for example, hello-world-*.jar), the build will fail:

> archiveArtifacts 'target/hello-world-*.jar'
No artifacts found that match the file pattern 'target/hello-world-*.jar'

Double-check your paths before committing.


9. View Pipeline Results

Once the pipeline completes successfully, Blue Ocean displays:

  • Build stage with archived artifacts
  • Unit Test stage with pass/fail details
  • A summary showing all tests passed

The image shows a Jenkins interface with a test summary indicating that all six tests have passed successfully.

In the classic UI, you can also review build history, visualize test trends, and download artifacts:

The image shows a Jenkins dashboard displaying the status of a project pipeline, including build history and test result trends. It highlights successful and failed stages in the pipeline process.


Additional Resources

Watch Video

Watch video content

Previous
Demo Controller Failure Pipeline Project