File tree Expand file tree Collapse file tree 2 files changed +37
-6
lines changed
Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -281,6 +281,43 @@ pipelines:
281281 tasks: # as usual
282282` ` `
283283
284+ # ## Error handling with on_error
285+
286+ When a pipeline fails due to a task error, you can optionally configure an `on_error` task that will be executed
287+ to handle the failure. This is useful for sending notifications, cleanup operations, or logging failure details.
288+
289+ ` ` ` yaml
290+ pipelines:
291+ deployment:
292+ tasks:
293+ build:
294+ script:
295+ - npm run build
296+ deploy:
297+ script:
298+ - ./deploy.sh
299+ depends_on:
300+ - build
301+ on_error:
302+ script:
303+ - echo "Deployment failed! Notifying team..."
304+ - curl -d "Deployment of {{.failedTaskName}} failed" ntfy.sh/mytopic
305+ ` ` `
306+
307+ The on_error task has access to special variables containing information about the failed task :
308+
309+ * `failedTaskName`: Name of the task that failed (key from `pipelines`)
310+ * `failedTaskExitCode`: Exit code of the failed task
311+ * `failedTaskError`: Error message of the failed task
312+ * `failedTaskStdout`: Standard output of the failed task
313+ * `failedTaskStderr`: Standard error output of the failed task
314+
315+ # ### Important notes:
316+
317+ * The `on_error` task only runs when a "normal" task in the pipeline fails
318+ * If the `on_error` task itself fails, the error will be logged but won't trigger another error handler
319+ * The `on_error` task has access to all the same job variables as regular tasks
320+ * Environment variables can be configured for the `on_error` task just like regular tasks
284321
285322# ## Configuring retention period
286323
Original file line number Diff line number Diff line change @@ -492,12 +492,6 @@ func (r *PipelineRunner) buildErrorGraph(job *PipelineJob) (*scheduler.Execution
492492 onErrorVariables ["failedTaskError" ] = failedTask .Error
493493 onErrorVariables ["failedTaskStdout" ] = string (failedTaskStdout )
494494 onErrorVariables ["failedTaskStderr" ] = string (failedTaskStderr )
495- } else {
496- onErrorVariables ["failedTaskName" ] = "task_not_identified_should_not_happen"
497- onErrorVariables ["failedTaskExitCode" ] = "99"
498- onErrorVariables ["failedTaskError" ] = "task_not_identified_should_not_happen"
499- onErrorVariables ["failedTaskStdout" ] = "task_not_identified_should_not_happen"
500- onErrorVariables ["failedTaskStderr" ] = "task_not_identified_should_not_happen"
501495 }
502496
503497 onErrorJobTask := jobTask {
You can’t perform that action at this time.
0 commit comments