A library must be tested on Node 18, 20 and 22, on Linux and Windows, but Node 18 on Windows is not supported. Design the stage.
IntermediateScenarioPipeline design & Jenkinsfile decisions
Answer
Situation read → Classic matrix with an exclusion.
What I'd do →
stage('Test') {
matrix {
axes {
axis { name 'NODE_VERSION'; values '18', '20', '22' }
axis { name 'PLATFORM'; values 'linux', 'windows' }
}
excludes {
exclude {
axis { name 'NODE_VERSION'; values '18' }
axis { name 'PLATFORM'; values 'windows' }
}
}
agent { label "${PLATFORM}" }
stages { stage('npm test') { steps { script {
if (isUnix()) { sh 'npm ci && npm test' } else { bat 'npm ci && npm test' }
} } } }
}
}
- Select Node per cell with nvm/fnm or a container image tag per version on Linux.
- Publish JUnit per cell so failures show which combination broke.
Why → matrix generates five parallel cells with readable names and no copy-pasted stages.
Interview tip → Mention isUnix() for cross-platform steps.
More on Pipeline design & Jenkinsfile decisions
A team's PR builds pile up: every push to an open PR starts a new 25-minute build while the old one keeps running. What do you change?BeginnerA deploy pipeline waits on `input` for approval, and on Monday you find 14 pods sitting idle since Friday. Fix it.IntermediateUnit tests, lint, dependency audit and SAST run sequentially and take 22 minutes. How do you restructure the pipeline?BeginnerDevelopers want to rerun only the deploy stage when it fails due to a flaky cluster API, without rebuilding the image. What do you offer?IntermediateA pipeline must run integration tests against a shared staging database that can only handle one test run at a time across four different repos. How do you coordinate?IntermediateYour 700-line Jenkinsfile now fails with `Method code too large!`. You need a fix today and a plan for next month.Advanced