Skip to content
Latchkey

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

Run this faster and cheaper on Latchkey managed runners. Start free →