Course contentsShow
← Cloud and Infrastructure
Lesson 1792 of 2,98937. JenkinsFree lesson

Parallel Stage Execution

Run multiple stages concurrently to reduce pipeline execution time and improve throughput.

Parallel Stage Execution

What you'll learn: How to run multiple pipeline stages simultaneously in Jenkins to speed up your builds and maximize resource utilization.


Why Run Stages in Parallel?

By default, Jenkins executes stages sequentially—one after another. But what if you have independent tasks like running unit tests, integration tests, and security scans that don't depend on each other? Running them one at a time wastes precious minutes. Parallel execution lets you run these stages concurrently, dramatically reducing total pipeline time.

Think of it like a restaurant kitchen: instead of one chef preparing appetizers, then main courses, then desserts in sequence, multiple chefs work simultaneously on different dishes. The meal gets to the table faster.


How Parallel Stages Work

In Declarative Pipeline syntax, you use the parallel directive inside a stage to define multiple sub-stages that execute at the same time. Each parallel branch runs independently on available agents.

pipeline {
    agent any
    stages {
        stage('Parallel Testing') {
            parallel {
                stage('Unit Tests') {
                    steps {
                        sh 'npm run test:unit'
                    }
                }
                stage('Integration Tests') {
                    steps {
                        sh 'npm run test:integration'
                    }
                }
                stage('Security Scan') {
                    steps {
                        sh 'npm audit'
                    }
                }
            }
        }
    }
}

All three test stages execute simultaneously. If one fails, Jenkins marks the parallel stage as failed but lets the others complete.


When to Use Parallel Execution

  • Independent test suites (unit, integration, functional)
  • Multi-platform builds (Linux, Windows, macOS simultaneously)
  • Environment deployments (dev and staging at once)
  • Resource-intensive tasks that don't share dependencies

Key Takeaway:
Parallel stage execution runs independent pipeline stages concurrently, reducing total build time and improving throughput by utilizing multiple agents or executors efficiently.