Code QuizAdvanced

CI Status From Piped Test Logs

A CI script pipes test output to a log file but reads the wrong exit code, hiding failures.

Codebash
#!/bin/bash
# CI step: run tests and record status

npm test | tee test-results.log

if [ $? -eq 0 ]; then
  echo "Build passing"
else
  echo "Build failing"
  exit 1
fi

Why can this CI step report 'Build passing' even when tests fail?