Builds are green even though the test step printed failures, because the test command's exit code is swallowed by a pipe. How do you make the pipeline honest?
BeginnerScenarioPipeline design & Jenkinsfile decisions
Answer
Situation read → sh 'npm test | tee test.log' returns the exit code of tee, not npm test.
What I'd do →
- Use
set -o pipefailwith bash:sh '''#!/bin/bash set -euo pipefail npm test | tee test.log ''' - Publish JUnit results with
allowEmptyResults: false, so missing reports also fail. - Review other
shsteps for|| trueand pipes.
Why → /bin/sh on many images is dash, which lacks pipefail; the shebang forces bash.
Interview tip → Mention both the shell issue and making test reports the source of truth.
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?IntermediateA 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.Intermediate