Blueprints

Using errorLogs function to send error message to Slack

Source

yaml
id: error-logs
namespace: company.team

tasks:
  - id: fail
    type: io.kestra.plugin.core.execution.Fail
    errorMessage: Something went wrong, make sure to fix it asap!

errors:
  - id: slack
    type: io.kestra.plugin.notifications.slack.SlackIncomingWebhook
    url: "{{ secret('SLACK_WEBHOOK') }}"
    payload: |
      {
        "text": "Failure alert for flow `{{ flow.namespace }}.{{ flow.id }}` with ID `{{ execution.id }}`. Here is a bit more context about why the execution failed: `{{ errorLogs()[0]['message'] }}`"
      }

About this blueprint

Fail Error

This fail task of the workflow will always fail. The error logs are captured using the errorLogs() function which is sent as a Slack alert message. The errorLogs() function retrieves a list of error logs from the failed task run. This is useful when sending alerts on failure. When using this function e.g. in a Slack alert message, you'll have the context about why the execution failed.

Fail

Slack Incoming Webhook

More Related Blueprints

New to Kestra?

Use blueprints to kickstart your first workflows.

Get started with Kestra