ForEach ​For​Each

yaml
type: "io.kestra.plugin.core.flow.foreach"
yaml
id: for_loop_example
namespace: company.team

tasks:
  - id: for_each
    type: io.kestra.plugin.core.flow.ForEach
    values: ["value 1", "value 2", "value 3"]
    tasks:
      - id: before_if
        type: io.kestra.plugin.core.debug.Return
        format: "Before if {{ taskrun.value }}"
      - id: if
        type: io.kestra.plugin.core.flow.If
        condition: '{{ taskrun.value == "value 2" }}'
        then:
          - id: after_if
            type: io.kestra.plugin.core.debug.Return
            format: "After if {{ parent.taskrun.value }}"

yaml
id: for_each_value
namespace: company.team

tasks:
  - id: for_each
    type: io.kestra.plugin.core.flow.ForEach
    values:
      - value 1
      - value 2
      - value 3
      - value 4
    concurrencyLimit: 2
    tasks:
      - id: return
        type: io.kestra.plugin.core.debug.Return
        format: "{{ task.id }} with value {{ taskrun.value }}"

yaml
id: parallel_tasks_example
namespace: company.team

tasks:
  - id: for_each
    type: io.kestra.plugin.core.flow.ForEach
    values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    concurrencyLimit: 2
    tasks:
      - id: parallel
        type: io.kestra.plugin.core.flow.Parallel
        tasks:
        - id: log
          type: io.kestra.plugin.core.log.Log
          message: Processing {{ parent.taskrun.value }}
        - id: shell
          type: io.kestra.plugin.scripts.shell.Commands
          commands:
            - sleep {{ parent.taskrun.value }}

yaml
id: loop_multiple_times
namespace: company.team

inputs:
  - id: s3_buckets
    type: ARRAY
    itemType: STRING
    defaults:
      - bucket1
      - bucket2

  - id: years
    type: ARRAY
    itemType: INT
    defaults:
      - 2025
      - 2026

  - id: months
    type: ARRAY
    itemType: STRING
    defaults:
      - March
      - April

tasks:
  - id: buckets
    type: io.kestra.plugin.core.flow.ForEach
    values: "{{inputs.s3_buckets}}"
    tasks:
      - id: year
        type: io.kestra.plugin.core.flow.ForEach
        values: "{{inputs.years}}"
        tasks:
          - id: month
            type: io.kestra.plugin.core.flow.ForEach
            values: "{{inputs.months}}"
            tasks:
              - id: full_table_name
                type: io.kestra.plugin.core.log.Log
                message: |
                  Full table name: {{parents[1].taskrun.value }}_{{parent.taskrun.value}}_{{taskrun.value}}
                  Direct/current loop (months): {{taskrun.value}}
                  Value of loop one higher up (years): {{parents[0].taskrun.value}}
                  Further up (table types): {{parents[1].taskrun.value}}
Properties
SubType
Min items 1
Default 1
Minimum >= 0
SubType
SubType