Flow icon
MailExecution icon

Executes flow on flow trigger with ExecutionLabels condition

Trigger a Kestra flow when any labeled execution fails and send an email alert, using the ExecutionLabels condition on a Flow trigger to scope by owner.

Categories
Core
id: flow-condition-executionlabels
namespace: company.team

triggers:
  - id: flow_trigger
    type: io.kestra.plugin.core.trigger.Flow
    dependsOn:
      - labels:
          owner: john.doe
        states:
          - FAILED

tasks:
  - id: send_email
    type: io.kestra.plugin.email.MailExecution
    to: john.doe@kestra.io
    from: hello@kestra.io
    subject: "The workflow execution {{ trigger.executionId }} failed for the flow
      {{ trigger.flowId }} in the namespace {{ trigger.namespace }}"
    host: mail.privateemail.com
    port: 465
    username: "{{ secret('EMAIL_USERNAME') }}"
    password: "{{ secret('EMAIL_PASSWORD') }}"
    executionId: "{{ trigger.executionId }}"

Get notified the moment a flow you care about fails, without polling or custom glue code. This blueprint listens across your Kestra instance for executions that carry a specific label and reach the FAILED state, then automatically sends a targeted email alert. It pairs the core io.kestra.plugin.core.trigger.Flow trigger with a dependsOn entry's labels field to scope alerting to exactly the workflows that matter, for example everything owned by a given team, so on-call engineers and flow owners hear about failures fast and stop chasing them in the UI.

How it works

  1. A io.kestra.plugin.core.trigger.Flow trigger watches all executions running on the instance.
  2. The trigger's dependsOn entry filters that stream to executions tagged with labels: {owner: john.doe}.
  3. The same entry only fires when a matching execution reaches one of the states listed, here FAILED.
  4. When fired, the send_email task (io.kestra.plugin.email.MailExecution) sends an alert over SMTP, building the subject from {{ trigger.executionId }}, {{ trigger.flowId }}, and {{ trigger.namespace }} and attaching the failed execution context via executionId.

What you get

  • Automatic email alerts on flow failure, scoped by label.
  • A subject line that names the failed execution, flow, and namespace.
  • Centralized, instance-wide failure detection with no per-flow wiring.
  • A reusable pattern for routing alerts by ownership.

Who it's for

  • Platform and data engineers running many flows who need failure visibility.
  • On-call and SRE teams that want label-scoped alerting.
  • Flow owners who only want to be paged about their own workflows.

Why orchestrate this with Kestra

Kestra's event-driven Flow trigger reacts to execution state changes the instant they happen, across every flow, something a single flow's own schedule cannot do. The declarative YAML keeps the alert rule version controlled and reviewable, the dependsOn entry's labels field gives you precise, label-based routing, and built-in retries plus full execution lineage mean alerts and their context are durable and auditable rather than fire-and-forget.

Prerequisites

  • A running Kestra instance with flows that carry labels (for example owner: john.doe).
  • SMTP server access (host, port, credentials) for outbound email.

Secrets

  • EMAIL_USERNAME: SMTP account username.
  • EMAIL_PASSWORD: SMTP account password.

Quick start

  1. Add the EMAIL_USERNAME and EMAIL_PASSWORD secrets to your Kestra instance.
  2. Update the to, from, host, and port values in the send_email task for your mail provider.
  3. Adjust the labels in the trigger's dependsOn entry to match the flows you want to monitor.
  4. Save the flow, then fail a labeled execution to confirm the alert email arrives.

How to extend

  • Watch additional states such as WARNING or KILLED.
  • Match multiple labels (for example owner plus team or env) in the labels field for tighter scoping.
  • Swap or add notification tasks for Slack, Microsoft Teams, or PagerDuty.
  • Add a remediation task to retry or restart the failed flow automatically.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.