New to Kestra?
Use blueprints to kickstart your first workflows.
Learn how to configure automatic task retries in Kestra with a constant backoff, max attempts, and a max duration so transient failures self-heal without manual intervention.
id: retries
namespace: company.team
tasks:
- id: fail_4_times
type: io.kestra.plugin.scripts.shell.Commands
taskRunner:
type: io.kestra.plugin.core.runner.Process
commands:
- if [ "{{ taskrun.attemptsCount }}" -eq 4 ]; then exit 0; else exit 1; fi
retry:
type: constant
interval: PT0.25S
maxAttempt: 5
maxDuration: PT1M
warningOnRetry: false
errors:
- id: will_never_happen
type: io.kestra.plugin.core.debug.Return
format: This will never be executed as retries will fix the issue
Transient failures are a fact of life in data and infrastructure pipelines: a flaky API, a brief network blip, or a service that is momentarily unavailable. This blueprint shows how to make a task self-heal by attaching a declarative retry policy to it, so Kestra automatically re-runs the task until it succeeds instead of failing the whole flow. It demonstrates a constant retry strategy with a fixed interval, a maximum attempt count, and a maximum total duration.
The flow contains a single shell task, fail_4_times, of type io.kestra.plugin.scripts.shell.Commands, executed with the io.kestra.plugin.core.runner.Process task runner. The command inspects {{ taskrun.attemptsCount }} and intentionally exits with a failure code until the 4th retry, then exits successfully on the 5th attempt. A retry block of type: constant drives the behavior: interval: PT0.25S waits a quarter second between tries, maxAttempt: 5 caps the number of attempts, maxDuration: PT1M bounds the total retry window to one minute, and warningOnRetry: false keeps retried executions from being flagged as warnings.
The flow also defines an errors branch, will_never_happen, of type io.kestra.plugin.core.debug.Return. Because the retries resolve the failure before the attempts are exhausted, this error handler is never triggered, illustrating that a successful retry keeps the execution green.
maxAttempt and maxDuration so flows fail fast when truly broken{{ taskrun.attemptsCount }} to reason about retry behaviorRetries in Kestra are declarative and live next to the task in plain YAML, with no custom wrapper scripts or sleep loops. You get strategy choices (constant, exponential, random), attempt and duration caps, lineage across every attempt in the execution UI, and full control over whether retries surface as warnings. Combined with event triggers, error branches, and visible execution history, this fills the gap left by tools whose own schedulers can only rerun an entire job rather than retry a single failing step with a bounded backoff policy.
Process task runner (no external services required)This flow references no secrets and needs no credentials to run.
fail_4_times retry every 0.25 seconds.constant strategy for exponential or random to space out retries.maxAttempt and maxDuration to match your tolerance for transient errors.warningOnRetry: true to flag executions that needed retries for observability.