Process Flow - Failing builds on test failures
Start Build
Run Tests
Tests Pass?
No→Fail 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.
pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'run-tests.sh'
}
}
}
post {
failure {
echo 'Build failed due to test failures'
}
}
}| Step | Action | Test Result | Build Status | Output |
|---|---|---|---|---|
| 1 | Start Build | N/A | Running | Build started |
| 2 | Run Tests | Tests running | Running | Executing run-tests.sh |
| 3 | Tests Pass? | Fail | Failing | Test failures detected |
| 4 | Fail Build | Fail | Failed | Build failed due to test failures |
| 5 | End | Fail | Failed | Build stopped |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| Test Result | N/A | Running | Fail | Fail |
| Build Status | Not started | Running | Failing | Failed |
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.