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.
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.
Start Jenkins using java -jar jenkins.war
command 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 name Stage_View_Example
.
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 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 stage1
is completed in 719ms
and stage2
is completed in 350ms
.
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