0
0
Jenkinsdevops~10 mins

Failing builds on test failures in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Failing builds on test failures
Start Build
Run Tests
Tests Pass?
NoFail Build
Yes
Pass Build
End
The build starts, runs tests, then checks if tests passed. If any test fails, the build fails; otherwise, it passes.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        sh 'run-tests.sh'
      }
    }
  }
  post {
    failure {
      echo 'Build failed due to test failures'
    }
  }
}
This Jenkins pipeline runs tests and fails the build if tests fail.
Process Table
StepActionTest ResultBuild StatusOutput
1Start BuildN/ARunningBuild started
2Run TestsTests runningRunningExecuting run-tests.sh
3Tests Pass?FailFailingTest failures detected
4Fail BuildFailFailedBuild failed due to test failures
5EndFailFailedBuild stopped
💡 Tests failed, so build fails and stops.
Status Tracker
VariableStartAfter Step 2After Step 3Final
Test ResultN/ARunningFailFail
Build StatusNot startedRunningFailingFailed
Key Moments - 2 Insights
Why does the build fail even if only one test fails?
Because the build checks the overall test result at Step 3 in the execution table; any failure causes the build to fail immediately.
What happens if all tests pass?
If tests pass at Step 3, the build status changes to Passed and continues to completion without failure.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the build status at Step 3 when tests fail?
APassed
BRunning
CFailing
DStopped
💡 Hint
Check the 'Build Status' column at Step 3 in the execution_table.
At which step does the build stop due to test failures?
AStep 2
BStep 5
CStep 3
DStep 4
💡 Hint
Look at the 'Output' and 'Build Status' columns to see when the build stops.
If the tests pass, how would the 'Build Status' change at Step 3?
APassed
BFailing
CRunning
DFailed
💡 Hint
Refer to the key moments explanation about test pass scenario.
Concept Snapshot
Jenkins build runs tests during pipeline.
If any test fails, build status changes to failed.
Use 'post { failure { ... } }' to handle failures.
Build stops immediately on test failure.
Ensures only passing code is deployed.
Full Transcript
In Jenkins, when you run a build pipeline, tests are executed as part of the process. The pipeline checks if tests pass or fail. If any test fails, the build is marked as failed and stops running further steps. This prevents broken code from moving forward. The pipeline can include a post-failure step to notify or log the failure. This flow ensures quality by stopping builds on test failures.