Skip to content
Latchkey

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 stage must contain exactly one of steps, parallel, matrix, or nested stages.
  • 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

  • stage names a phase; steps runs 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

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card