Commands icon
Process icon
SlackIncomingWebhook icon

Error handling: send Slack alert on failure

Trigger a Slack alert when a Kestra workflow fails. A simple, reusable failure notification pattern for monitoring production pipelines.

Categories
Core
id: on-failure-alert
namespace: company.team

tasks:
  - id: fail
    type: io.kestra.plugin.scripts.shell.Commands
    taskRunner:
      type: io.kestra.plugin.core.runner.Process
    commands:
      - exit 1

errors:
  - id: slack
    type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
    url: "{{ secret('SLACK_WEBHOOK') }}"
    messageText: "Failure alert for flow {{ flow.namespace }}.{{ flow.id }} with ID
      {{ execution.id }}"

Get notified in Slack the moment a workflow breaks. This blueprint shows the Kestra error-handling pattern: a flow runs its normal tasks, and if anything fails, the errors block fires a Slack message that names the namespace, flow ID, and execution ID so on-call engineers can jump straight to the failed run. It turns silent pipeline failures into actionable alerts and gives any team a reusable, copy-paste failure notification pattern for production monitoring.

How it works

  • The main task fail is an io.kestra.plugin.scripts.shell.Commands task running on the io.kestra.plugin.core.runner.Process runner. Here it simply runs exit 1 to simulate a failure, standing in for whatever real work your pipeline does.
  • When any task in the flow fails, Kestra runs the tasks declared under the top-level errors block.
  • The error task slack of type io.kestra.plugin.slack.notifications.SlackIncomingWebhook posts to an incoming webhook URL pulled from a secret.
  • The messageText is templated with Pebble expressions ({{ flow.namespace }}, {{ flow.id }}, {{ execution.id }}) so each alert carries the exact context needed to find and debug the failed execution.

What you get

  • Instant Slack notifications whenever a workflow fails.
  • Alerts that include namespace, flow ID, and execution ID for fast triage.
  • A drop-in errors pattern you can paste into any flow.
  • No polling or external monitoring service to maintain.

Who it's for

  • Data and platform engineers running production pipelines who need to know about failures fast.
  • On-call and SRE teams that triage incidents from Slack.
  • Anyone standardizing observability and alerting across many Kestra flows.

Why orchestrate this with Kestra

Slack has no idea your pipeline failed. Kestra closes that gap. The declarative errors block runs only on failure, with no extra cron job or babysitting script, and the alert is wired directly to execution lineage so the message links back to the exact run. Combine it with task retries to alert only after retries are exhausted, attach event triggers to chain recovery flows, and keep the whole pattern as version-controlled YAML that any team can reuse.

Prerequisites

  • A running Kestra instance.
  • The Slack plugin (bundled in the default Kestra distribution).
  • A Slack incoming webhook URL for the channel that should receive alerts.

Secrets

  • SLACK_WEBHOOK: the Slack incoming webhook URL used by the slack error task.

Quick start

  1. Create a Slack incoming webhook and copy its URL.
  2. Store it as the SLACK_WEBHOOK secret in your Kestra instance.
  3. Add this flow and execute it. The fail task runs exit 1, so the run fails on purpose.
  4. Check your Slack channel for the alert naming the namespace, flow, and execution ID.

How to extend

  • Replace the fail task with your real pipeline logic and keep the errors block as-is.
  • Add retries to your tasks so alerts fire only after retries are exhausted.
  • Customize messageText to add run duration, the failing task ID, or a direct link to the execution.
  • Add more error tasks (email, PagerDuty, a webhook) alongside Slack for layered alerting.
  • Swap SlackIncomingWebhook for a richer Slack message task to post formatted blocks and buttons.

Links

Orchestrate with Kestra
Orchestrate Slack with Kestra
Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.