Table of Contents
- Initial Pipeline Configuration
- Adding Parallel Unit Tests
- [Understanding the Node 20 Failure](#understanding-the-node 20-failure)
- [Fixing Dependencies for Node 20](#fixing-dependencies-for-node 20)
- Complete Refactored Pipeline
- Links and References
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
You can learn more about the Jenkins Kubernetes Plugin here.
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: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:Complete Refactored Pipeline
Putting it all together:Links and References
- Jenkins Pipeline Documentation
- Kubernetes Plugin for Jenkins
- Node.js Official Docker Images
- Mocha Test Framework