Stages and Steps
Learn the concepts, syntax containment blocks, visual milestones, and linear execution boundaries required to group and organize pipeline workflows.
What are Stages and Steps?
Inside a Declarative Jenkinsfile, execution flow is broken down into structured hierarchies to ensure scannability and clear logs. The work of a continuous automation pipeline is divided into major structural phases called Stages, which contain the individual core actions called Steps.
Containment Structure Blocks
Jenkins maps out the pipeline lifecycle using explicit nested code definitions:
- The `stages` Collection Block: A primary mandatory container wrapper that holds the chronological array list of every single processing phase in the pipeline.
- The Individual `stage` Milestones: Explicitly named logical buckets (e.g., `stage('Run Linters')`) that isolate specific business tasks and generate dedicated tracking blocks in the Blue Ocean or Stage View UI.
- The Nested `steps` Directive Block: An inner block container that seals and validates the granular script lines, preventing commands from running floating outside an active stage.
- The Core Task Steps: The atomic action commands—such as invoking shell environments via
sh, logging strings viaecho, or archiving files viaarchiveArtifacts.
Key Concepts
Linear Stage Halting Gates
Understanding that stages execute sequentially from top to bottom. If an individual step within any stage throws an error, the remaining steps are dropped and subsequent stages are completely blocked.
Visual Stage View Auditing
Leveraging separate stage names to view localized metrics on the Jenkins dashboard, making it simple to trace execution times or pinpoint where a build broke.
Practical Jenkins Example
The following declarative pipeline showcases how multiple distinct stages organize a build, test, and release sequence with linear step scripts:
pipeline {
agent any
// Primary container block holding the linear workflow array
stages {
stage('Fetch and Compile Source') {
steps {
echo 'Step Action: Fetching commit footprint layers...'
sh 'echo "Simulating project source compilation..."'
}
}
stage('Execute Quality Controls') {
steps {
echo 'Step Action: Initializing static analysis linter rules...'
echo 'Step Action: Spawning unit regression tests...'
sh 'echo "All test files verified successfully."'
}
}
stage('Publish Release Assets') {
steps {
echo 'Step Action: Pushing compiled binaries out to environment hubs...'
sh 'echo "Release lifecycle wrapped up clean."'
}
}
}
}
Practice Exercise: Deploy and Inspect a Multi-Stage Sequence
Step-by-Step Task Sequence:
- Open the script block workspace of an active test pipeline or configure a new Pipeline item from your dashboard interface.
- Copy-paste the complete practical multi-stage declarative code snippet provided in the example section above directly into your script text terminal window and click Save.
- Trigger a manual validation run path by selecting the Build Now sidebar action link.
- Return to the primary status panel view of your job to observe how the Stage View table renders three independent column milestones.
- Click the current build run's tracking number box, open Console Output, and trace how individual log steps are nested under their respective stage headers.
Summary
You have completed the Stages and Steps lesson. Continue through the syllabus to learn how to manage dynamic values and credentials inside your scripts by exploring the Environment Variables lesson.