Add conditions to workflows
Conditions decide what a workflow does with the data it receives. With conditions, a workflow runs only for matching events, skips or branches between steps, repeats steps while a check is true, and keeps only the array items that match. Learn where to add each kind of condition, how to write it in KQL, and which length limits apply.
| To | Add the condition to | It can check |
|---|---|---|
|
|
The trigger's on.condition |
The fields of the trigger's event, such as event.workflow.name |
| Run or skip one step | The step's if parameter |
The workflow's data, such as inputs, consts, event, and the output of earlier steps |
| Run one set of steps or another | An if step's condition |
The workflow's data |
| Repeat steps while something is true | A while step's condition |
The workflow's data, after each iteration |
| Keep or find the items in an array that match | A data.filter or data.find step's condition |
Each item, as item, and its position, as index |
To run a workflow only for some events, add a KQL query to the trigger's on.condition. The query can use any field in the trigger's event, with the event. prefix. Without a condition, the workflow runs for every event.
For example, to run the workflow only when a specific workflow fails:
triggers:
- type: workflows.failed
on:
condition: "event.workflow.name : 'ops--rollback-deployment'"
Kibana checks the condition as written, so it can't include {{ }} templating. If Kibana can't evaluate the query, the workflow doesn't run for that event, and Kibana logs a warning in its server log.
To find the fields that each trigger's event includes, refer to Event-driven triggers.
Unlike trigger conditions, step conditions can include {{ }} values in their KQL. if and while conditions can also be a ${{ }} expression that evaluates to a boolean. For how each step uses its condition, refer to these pages:
ifstep and step-levelif: Branch between two sets of steps, or skip a single step.whilestep: Repeat steps while the condition is true. Kibana checks the condition after each iteration, so the steps always run at least once.data.filteranddata.findsteps: Keep or find the items in an array that match the condition.
Every kind of condition accepts a KQL query. The if and while conditions also accept a ${{ }} expression that evaluates to true or false. In KQL, use : for equality, as in event.status: "closed". For the operators that workflows support, such as ranges, wildcards, and and, or, and not, refer to Supported KQL features.
Put quotes around the whole condition, because YAML otherwise reads the : in KQL as the beginning of a new key. If the condition contains double quotes, use single quotes around it, as in condition: 'event.workflow.name: "ops--rollback-deployment"'.
The maximum length of a condition depends on where you add it:
| Condition | Maximum length |
|---|---|
Trigger on.condition |
Varies by deployment and version: |
Step-level if and the if step's condition |
2,000 characters. To work around the limit, refer to Use a condition longer than 2,000 characters. |
while, data.filter, and data.find conditions |
No limit |