An Introduction to Blue Ocean: The Jenkins UI

Updated: February 3, 2024 By: Guest Contributor Post a comment

Introduction

Jenkins, the open-source automation server, has long been a cornerstone of the DevOps world, facilitating continuous integration and continuous delivery (CI/CD) for software projects with its vast array of plugins and flexible configuration options. However, its traditional user interface (UI) was often criticized for being less intuitive and visually appealing. Enter Blue Ocean: a plugin that reimagines the Jenkins UI, aiming to enhance user experience and streamline CI/CD pipelines. This tutorial introduces Blue Ocean, guiding you through its installation, basic features, and showcasing how to create and visualize CI/CD pipelines.

Installation

Before diving into Blue Ocean, ensure Jenkins is installed. If it’s not, download it from Jenkins official site. Once Jenkins is running, install the Blue Ocean plugin. Navigate to the Jenkins Dashboard, go to ‘Manage Jenkins’ > ‘Manage Plugins’, and search for ‘Blue Ocean’ in the ‘Available’ tab. Install it alongside any dependencies. After installation, the Blue Ocean interface can be accessed through the Jenkins dashboard or by appending ‘/blue’ to your Jenkins server’s URL.

Creating a New Pipeline

One of the core features of Blue Ocean is its streamlined pipeline creation process. To create a new pipeline:

  1. Go to the Blue Ocean UI.
  2. Click on ‘New Pipeline’.
  3. Select your repository host (e.g., GitHub, Bitbucket).
  4. Follow the on-screen instructions to connect your repository. This might involve providing an access token or installing a Jenkins app on your repository host.
  5. After connecting your repository, choose the one containing your project.
  6. Blue Ocean will then scan the repository for a Jenkinsfile, which contains the pipeline definition. If it doesn’t find one, it offers to help create it.

It’s that simple. Blue Ocean emphasizes clarity and efficiency from creation to execution of pipelines.

Visualizing Pipelines

The visualization feature is a highlight of Blue Ocean, offering a clean, easily navigable interface for monitoring your pipelines. Each stage of the pipeline is represented visually, providing immediate feedback on the status of each step (e.g., success, failure, in progress). This feature significantly aids in diagnosing issues and streamlining pipeline performance.

Declarative Pipeline Syntax

Jenkinsfiles, which define pipelines, can use a declarative syntax making them more readable and easier to write. Here is a basic example:

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
    stage('Test') {
      steps {
        echo 'Testing...'
      }
    }
    stage('Deploy') {
      steps {
        echo 'Deploying...'
      }
    }
  }
}

This simple pipeline outlines three stages: Build, Test, and Deploy. The ‘echo’ command simulates actions typically performed at each stage.

Advanced Pipeline Features

Blue Ocean builds on basic pipeline features by introducing advanced functionalities like parallel builds, post-build actions, and environment management. The following example demonstrates a pipeline with parallel builds and post-build actions:

pipeline {
  agent any
  stages {
    stage('Parallel Build') {
      parallel {
        stage('Frontend') {
          steps {
            echo 'Building frontend...'
          }
        }
        stage('Backend') {
          steps {
            echo 'Building backend...'
          }
        }
      }
    }
    stage('Test') {
      steps {
        script {
          // Complex testing logic here
        }
      }
    }
  }
  post {
    success {
      echo 'Build successful!'
    }
    failure {
      echo 'Build failed.'
    }
  }
}

This example highlights the capability to execute frontend and backend builds in parallel, reducing overall build time. The ‘post’ section demonstrates actions based on the build outcome.

Conclusion

Blue Ocean elegantly simplifies Jenkins’ UI, making it more accessible and enjoyable for users to create, visualize, and manage their CI/CD pipelines. Its intuitive design and powerful features help democratize automation, enabling teams to focus on what matters most: building great software.