ForEach​For​Each

Execute a group of tasks for each value in the list.

You can control how many task groups are executed concurrently by setting the concurrencyLimit property.

  • If you set the concurrencyLimit property to 0, Kestra will execute all task groups concurrently for all values.
  • If you set the concurrencyLimit property to 1, Kestra will execute each task group one after the other starting with the task group for the first value in the list.

Regardless of the concurrencyLimit property, the tasks will run one after the other — to run those in parallel, wrap them in a Parallel task as shown in the last example below (see the flow parallel_tasks_example).

The values should be defined as a JSON string or an array, e.g. a list of string values ["value1", "value2"] or a list of key-value pairs [{"key": "value1"}, {"key": "value2"}].

You can access the current iteration value using the variable {{ taskrun.value }} or {{ parent.taskrun.value }} if you are in a nested child task. You can access the batch or iteration number with {{ taskrun.iteration }}.

If you need to execute more than 2-5 tasks for each value, we recommend triggering a subflow for each value for better performance and modularity. Check the flow best practices documentation for more details.

yaml
type: "io.kestra.plugin.core.flow.ForEach"