Parallel Stages

Run independent stages at the same time with parallel to make your pipeline faster.

Syntaxstage('Tests') { parallel { stage('Unit') { steps { sh '...' } } stage('Lint') { steps { sh '...' } } } }

When stages do not depend on each other, you can run them at the same time using the parallel block. This shortens total pipeline time.

When to use it

  • Running unit, integration, and lint checks together.
  • Testing on multiple operating systems or versions.
  • Building several independent components.

How it works

Inside a stage, replace steps with parallel and list sub-stages. Jenkins runs them concurrently, each on its own executor, and the stage completes when all branches finish.

Example

Example · bash
pipeline {
    agent any
    stages {
        stage('Quality Checks') {
            parallel {
                stage('Unit Tests') {
                    steps { sh 'npm run test:unit' }
                }
                stage('Lint') {
                    steps { sh 'npm run lint' }
                }
                stage('Type Check') {
                    steps { sh 'npm run typecheck' }
                }
            }
        }
    }
}

When to use it

  • A Node.js project runs unit tests, ESLint, and TypeScript type-checking in parallel, cutting the check stage from 6 minutes to 2.
  • A multi-platform build compiles binaries for Linux, macOS, and Windows simultaneously on three different agents.
  • A pipeline runs security scanning and SAST in parallel with unit tests to keep overall pipeline time under 10 minutes.

More examples

Parallel test branches

Runs unit tests, lint, and type-checking in parallel so all three execute at the same time.

Example · groovy
stage('Parallel Tests') {
  parallel {
    stage('Unit')  { steps { sh 'npm test' } }
    stage('Lint')  { steps { sh 'npm run lint' } }
    stage('Types') { steps { sh 'npx tsc --noEmit' } }
  }
}

Parallel builds on different agents

Dispatches Linux and Windows builds to separate labeled agents and runs them simultaneously.

Example · groovy
stage('Cross-Platform Build') {
  parallel {
    stage('Linux') {
      agent { label 'linux' }
      steps { sh 'make linux' }
    }
    stage('Windows') {
      agent { label 'windows' }
      steps { bat 'build.bat' }
    }
  }
}

Fail-fast parallel with catch

Sets failFast true so that if any parallel branch fails, Jenkins aborts the remaining branches immediately.

Example · groovy
stage('Test Suite') {
  failFast true
  parallel {
    stage('Fast Tests') { steps { sh './test-fast.sh' } }
    stage('Slow Tests') { steps { sh './test-slow.sh' } }
  }
}

Discussion

  • Be the first to comment on this lesson.