How to Use Stages and Steps in a Jenkins Pipeline
In Jenkins, a stage is a named phase shown on the pipeline graph, and steps are the actual commands run inside it.
Each stage groups a unit of work and appears as a column in the Stage View. Inside, steps holds the sh, echo, or plugin calls that execute.
Stages with steps
Three stages render as three columns; the steps inside each do the work.
Jenkinsfile
pipeline {
agent any
stages {
stage('Install') {
steps {
sh 'npm ci'
}
}
stage('Lint') {
steps {
sh 'npm run lint'
}
}
stage('Test') {
steps {
echo 'Running tests'
sh 'npm test'
}
}
}
}Gotchas
- A
stagemust contain exactly one ofsteps,parallel,matrix, or nestedstages. - Stage names show in the UI; keep them short and descriptive.
- A failing step fails its stage and, by default, stops the pipeline.
Key takeaways
stagenames a phase;stepsruns the commands.- Each stage holds one of steps, parallel, matrix, or nested stages.
- A failed step fails the stage and halts the pipeline by default.
Frequently asked questions
How do I use Stages and Steps in a Jenkins Pipeline?
Each stage groups a unit of work and appears as a column in the Stage View. Inside, steps holds the sh, echo, or plugin calls that execute.
Stages with steps?
Three stages render as three columns; the steps inside each do the work.
Related guides
How to Use a Matrix in a Jenkins Declarative PipelineUse the matrix directive in a Jenkins declarative pipeline to run a set of stages across axis combinations li…
How to Run a Postgres Service in a Jenkins PipelineRun a Postgres service in a Jenkins pipeline using docker.image().withRun via the Docker Pipeline plugin so i…
How to Publish a Coverage Report in a Jenkins PipelinePublish a code-coverage report in a Jenkins pipeline with the Coverage plugin recordCoverage step, parsing Co…