Working with stage view in Jenkins 2.0 for a pipeline project

Jenkins is an open-source automation tool used to build, test and deploy code. In this answer, we will learn how to use stages and view them visually while running the Jenkins pipeline.

Jenkins stage view helps us to understand easily which step is running currently with visual representation.

Syntax

We can create stages in the Jenkins pipeline using the below syntax. We will add each stage under the stages section.

stages {
stage('Provide stage name here') {
steps {
echo 'Define your steps here'
}
}
}
Stages in Jenkins

Let us take a look at an example of this.

Example

  1. Start Jenkins using java -jar jenkins.war command or any other way you prefer.

  2. Click the button "New Item" on the Jenkins home page as shown below.

"New Item" button on home page
  1. Provide a name to the pipeline, select Pipeline, and click "OK" to create a pipeline as shown below. Here we create a pipeline with the name Stage_View_Example.

Create pipeline
Create pipeline
  1. Now, go to the Pipeline section and provide the below code to create a pipeline with stage1 and stage2. Click "Apply" and "Save."

pipeline {
agent any
stages {
stage('Stage1') {
steps {
echo 'Hello this is the first stage.'
}
}
stage('Stage2') {
steps {
echo 'This is the second stage.'
}
}
}
}
Creating pipelines with stages
Pipeline configuration
  1. Click Build Now to run the pipeline. Once the pipeline starts running it will show the stage view as shown below. We can see that stage1 is completed in 719ms and stage2 is completed in 350ms.

Build to run the pipeline
  1. We can also view the logs for each stage by hovering on the stage and clicking the "Logs" button. It will then display the logs for that stage as shown below.

Stage Logs

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved