Skip to main content
In this guide, we’ll refactor our Jenkins pipeline so that the Unit Testing stage runs concurrently on Node.js 18, 19, and 20. This approach speeds up feedback and ensures compatibility across multiple runtime versions.

Table of Contents


Initial Pipeline Configuration

We start with a simple declarative pipeline using a Kubernetes agent that defaults to a Node 18 container. By default, all steps in the Unit Testing stage will run on Node 18.
All unit tests will execute inside the node-18 container by default.
You can learn more about the Jenkins Kubernetes Plugin here.

Adding Parallel Unit Tests

To run tests on multiple Node.js versions simultaneously, we replace the single Unit Testing stage with parallel sub-stages:

Understanding the Node 20 Failure

When the Node 20 stage runs as a separate Docker container, you might encounter:
The error occurs because npm install was only executed in the Kubernetes Pod (Node 18/19). The separate Node 20 container has no node_modules directory.
Docker agents do not share volumes with your Kubernetes Pod. Make sure to install dependencies inside every container or orchestrate a shared volume mount.

Fixing Dependencies for Node 20

Quick Fix: Inline npm install

Add the install step directly to the Node 20 stage:

Cleaner Approach: Separate Install & Test Sub-Stages

Within the parallel group for Node 20, create two sub-stages—one for installing dependencies, one for running tests:
This structure ensures each Node.js container installs its own dependencies and runs tests in isolation.

Complete Refactored Pipeline

Putting it all together:

Watch Video