Skip to content
Latchkey

How to Continue a Pipeline After a Failure With catchError in Jenkins

catchError runs a block and records a failure as a chosen result instead of immediately aborting the pipeline.

Wrap risky steps in catchError(buildResult: '...', stageResult: '...'). The block can fail without stopping the run, so cleanup, reporting, or notification stages still execute.

Steps

  • Wrap the failing-prone steps in a catchError(...) block.
  • Set buildResult (e.g. UNSTABLE) and stageResult (e.g. FAILURE).
  • Put report or notify stages after it so they still run.

Jenkinsfile

Jenkinsfile
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
          sh 'npm test'
        }
      }
    }
    stage('Publish report') {
      steps {
        junit 'reports/*.xml'
      }
    }
  }
}

Gotchas

  • For non-fatal cleanup, warnError('message') is a shorter form that marks the build unstable.
  • A swallowed failure can hide real regressions; scope catchError narrowly.

Related guides

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