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'}}}
Let us take a look at an example of this.
Example
Start Jenkins using
java -jar jenkins.warcommand or any other way you prefer.Click the button "New Item" on the Jenkins home page as shown below.
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 nameStage_View_Example.
Now, go to the
Pipelinesection and provide the below code to create a pipeline withstage1andstage2. Click "Apply" and "Save."
pipeline {agent anystages {stage('Stage1') {steps {echo 'Hello this is the first stage.'}}stage('Stage2') {steps {echo 'This is the second stage.'}}}}
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
stage1is completed in719msandstage2is completed in350ms.
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.
Free Resources