0
0
Jenkinsdevops~10 mins

Stage block structure in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Stage block structure
Start Pipeline
Enter stages block
Execute stage 1
Execute stage 2
... more stages ...
Exit stages block
End Pipeline
The pipeline starts, enters the stages block, executes each stage in order, then exits the stages block and ends.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps { echo 'Building...' }
    }
  }
}
This pipeline runs one stage named 'Build' that prints 'Building...'.
Process Table
StepBlock EnteredActionOutputNext Step
1pipelineStart pipeline executionPipeline startedEnter stages block
2stagesEnter stages blockReady to run stagesEnter stage 'Build'
3stage('Build')Run steps blockPrints: Building...Exit stage 'Build'
4stage('Build')Exit stage blockStage 'Build' completeExit stages block
5stagesExit stages blockAll stages completeEnd pipeline
6pipelineEnd pipeline executionPipeline finishedStop
💡 All stages executed, pipeline ends normally
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
pipeline_stateNot startedRunningRunningRunningFinished
current_blockNonestagesstage('Build')stagesNone
stage_statusNonePendingRunningCompleteComplete
Key Moments - 2 Insights
Why does the pipeline enter the 'stages' block before running any stage?
The 'stages' block groups all stages together. Execution must enter it first to know which stages to run, as shown in step 2 of the execution table.
What happens if there are multiple stages inside the 'stages' block?
Each stage runs one after another inside the 'stages' block. The pipeline enters each stage block in order, runs its steps, then moves to the next stage, similar to step 3 and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the 'current_block' after step 3?
Astages
Bpipeline
Cstage('Build')
DNone
💡 Hint
Check the 'current_block' column in variable_tracker after step 3
At which step does the pipeline finish execution?
AStep 5
BStep 6
CStep 4
DStep 3
💡 Hint
Look at the 'pipeline_state' variable in variable_tracker and the 'Action' column in execution_table
If a second stage is added after 'Build', what will happen after step 4?
ANext stage block starts executing
BStages block exits
CPipeline ends immediately
DPipeline restarts
💡 Hint
Refer to the concept_flow and execution_table steps for multiple stages
Concept Snapshot
pipeline {
  agent any
  stages {
    stage('Name') {
      steps { ... }
    }
  }
}

- 'stages' groups multiple 'stage' blocks
- Each 'stage' runs sequentially
- Steps inside 'stage' execute commands
- Pipeline ends after all stages complete
Full Transcript
The Jenkins pipeline starts by entering the pipeline block. Inside it, the stages block groups all stages. The pipeline enters the stages block, then executes each stage one by one. For each stage, it runs the steps defined inside. After finishing all stages, the pipeline exits the stages block and ends. Variables like current_block and stage_status track which part is running. This structure helps organize tasks clearly and run them in order.