How to Mark a Build Unstable With warnError in Jenkins
warnError runs a block and, on failure, logs a message and sets the build result to UNSTABLE rather than FAILURE.
Use warnError('message') { ... } so a flaky or advisory step turns the build yellow (UNSTABLE) instead of red. The pipeline keeps going and the message lands in the log.
Steps
- Identify a step whose failure should warn, not block.
- Wrap it in
warnError('reason') { }. - Distinguish UNSTABLE from FAILURE in your downstream gating.
Jenkinsfile
Jenkinsfile
pipeline {
agent any
stages {
stage('Lint') {
steps {
warnError('Lint reported issues') {
sh 'npm run lint'
}
}
}
}
post {
unstable { echo 'Build is unstable: review the lint output.' }
}
}Gotchas
- warnError always sets UNSTABLE; use catchError if you need a different result.
- An UNSTABLE result still counts as a non-success in many downstream checks.
Related guides
How to Continue a Pipeline After a Failure With catchError in JenkinsLet a Jenkins stage fail without aborting the whole pipeline using catchError, marking the build unstable whi…
How to Capture the Exit Code and Output of sh in JenkinsCapture a shell command exit code with returnStatus and its output with returnStdout in a Jenkins pipeline, s…