Interview Prep/Jenkins/Pipeline design & Jenkinsfile decisions

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 →

  1. Use set -o pipefail with bash:
    sh '''#!/bin/bash
    set -euo pipefail
    npm test | tee test.log
    '''
    
  2. Publish JUnit results with allowEmptyResults: false, so missing reports also fail.
  3. Review other sh steps for || true and 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.

All Jenkins questions Roadmap: Jenkins

More on Pipeline design & Jenkinsfile decisions