Pipeline Stages
Stages are the building blocks of a Jenkins Pipeline. They organize your build process into logical steps, and Jenkins visualizes them in the UI. This chapter dives into stages, parallel execution, and optional stagelevel tools.
Basic Stages
In Declarative, each
stage must have a name and contain steps.stages {
stage('Build') {
steps { sh 'make build' }
}
stage('Test') {
steps { sh 'make test' }
}
}Parallel Stages
To speed up pipelines, run multiple stages concurrently using
parallel.stages {
stage('Parallel Tests') {
parallel {
stage('Unit Tests') {
steps { sh 'npm test' }
}
stage('Integration Tests') {
steps { sh 'npm run test:integration' }
}
}
}
}StageLevel Agent
You can override the pipeline agent at the stage level. For example, run the build on a Linux agent, but run a stage on a Windows agent.
pipeline {
agent none
stages {
stage('Build on Linux') {
agent { label 'linux' }
steps { sh 'make' }
}
stage('Test on Windows') {
agent { label 'windows' }
steps { bat 'tests.bat' }
}
}
}Post Stage Actions
Use
post at the pipeline level, but you can also have stagelevel post for cleanup after a stage.stage('Deploy') {
steps { ... }
post {
success { echo 'Deployment succeeded' }
failure { echo 'Deployment failed' }
}
}Viewing Stage Visualization
After running a pipeline, Jenkins shows a stage view with each stage’s duration and status (green = success, red = failure). Blue Ocean plugin gives a modern graphical view.
Two Minute Drill
- Stages organize pipeline steps into logical groups.
- Use
parallelto run stages concurrently. - Override agent per stage for different build environments.
- Stagelevel
posthandles success/failure per stage. - Stage view visualizes pipeline progress.
Need more clarification?
Drop us an email at career@quipoinfotech.com
