Schedule icon
Log icon

Run the task based on runIf condition

Use the Kestra runIf attribute to conditionally execute tasks. Build dynamic workflows that skip or run steps based on runtime conditions.

Categories
Core
id: runif-task-attribute
namespace: company.team

triggers:
  - id: schedule
    type: io.kestra.plugin.core.trigger.Schedule
    cron: 0 10 * * *
    inputs:
      run_everything: true

inputs:
  - id: run_everything
    type: BOOL
    defaults: true

tasks:
  - id: step1
    type: io.kestra.plugin.core.log.Log
    message: "This will always run"

  - id: step2
    type: io.kestra.plugin.core.log.Log
    runIf: "{{ inputs.run_everything }}"
    message: "This will only run if set to true"

Conditionally execute individual tasks at runtime using the runIf attribute in Kestra. This flow shows how to skip or run a step based on a boolean input, so you can build one workflow that runs end to end or only selected parts depending on how it is triggered. It is the lightweight alternative to wrapping a single task inside an io.kestra.plugin.core.flow.If block, keeping declarative YAML flat and readable while still giving you full conditional control over execution.

How it works

The flow declares a single run_everything input of type BOOL that defaults to true. It then defines two io.kestra.plugin.core.log.Log tasks:

  1. step1 always runs and logs a confirmation message.
  2. step2 carries runIf: "{{ inputs.run_everything }}", so it only executes when the input evaluates to true. When the condition is false, Kestra marks the task as skipped rather than failed.

A io.kestra.plugin.core.trigger.Schedule trigger fires every day at 0 10 * * * and passes run_everything: true, so scheduled runs always execute every task. Manual runs can flip the input to false to skip the conditional step.

What you get

  • Per-task conditional execution without nesting tasks inside an If block.
  • A clear skipped state in the execution UI when a condition is not met.
  • A scheduled run that exercises the full flow plus a manual debug path that runs only part of it.
  • A reusable pattern that works on any task type, not just logging.

Who it's for

  • Data and platform engineers who want clean, flat conditional pipelines.
  • Teams maintaining one flow for both full production runs and partial debug runs.
  • Anyone replacing verbose If wrappers around a single conditional task.

Why orchestrate this with Kestra

Kestra makes conditional logic declarative: runIf is a property on the task itself, evaluated against runtime inputs, trigger payloads, or upstream outputs. You get event and schedule triggers, automatic retries, full execution lineage, and a visual topology, all from YAML. A plain scheduler or cron job cannot express per-task conditions, surface a skipped state, or branch a single definition between full and partial runs without custom scripting. Kestra handles that natively.

Prerequisites

  • A running Kestra instance.

Secrets

This flow uses no secrets.

Quick start

  1. Add the flow to a namespace in your Kestra instance.
  2. Execute it manually with run_everything set to true and confirm both tasks run.
  3. Execute again with run_everything set to false and confirm step2 is skipped.
  4. Leave the Schedule trigger enabled to run the full flow daily at 10:00.

How to extend

  • Swap the Log tasks for real work such as database writes, API calls, or file processing.
  • Drive runIf from upstream task outputs or trigger variables instead of a static input.
  • Combine several runIf conditions to assemble feature-flag style pipelines.
  • Use runIf alongside io.kestra.plugin.core.flow.If when you need to gate multiple tasks at once.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.