Consider a Jenkins pipeline with a test stage that runs unit tests using a shell command. If some tests fail, what will Jenkins do by default?
stage('Test') { steps { sh 'pytest tests/' } }
Think about how shell commands signal failure in Jenkins pipelines.
By default, Jenkins treats any non-zero exit code from a shell command as a failure, causing the build to fail and stop.
You want Jenkins to run tests and fail the build if any test fails, using the JUnit plugin to parse test reports. Which post-build action configuration ensures this?
Look for the option that causes build failure on test failures in the JUnit plugin settings.
Checking 'Fail the build if test results are unstable' causes Jenkins to mark the build as failed if any test fails.
You have a Jenkins pipeline running tests with a shell command. Tests fail, but the build still shows success. What is the most likely cause?
stage('Test') { steps { sh(script: 'pytest tests/', returnStatus: true) } }
Check how the shell step handles exit codes with 'returnStatus'.
Using 'returnStatus: true' makes the shell step return the exit code instead of failing the build automatically. The pipeline must check the code to fail explicitly.
You run tests in a Jenkins pipeline using a shell step with 'returnStatus: true' to capture exit code. How do you fail the build if tests fail?
stage('Test') { steps { script { def status = sh(script: 'pytest tests/', returnStatus: true) // What to do here? } } }
Think about how to make the pipeline fail explicitly based on a variable.
Using 'error()' in the pipeline script causes the build to fail immediately with a message.
Which approach best ensures Jenkins build fails on test failures and provides clear test reports in the UI?
Consider both failing the build and showing test results in Jenkins UI.
Capturing exit code ensures build fails on test failures; publishing JUnit reports with failure option shows detailed test results and fails build properly.