Loops

Use for: in steps to invoke tasks repeatedly with different loop variables.

Examples

  name: List Loop Example

vars:
  components:
    - src/main
    - src/utils
    - src/api

tasks:
  build:
    aliases: [default]
    desc: Build all components
    steps:
      - for: component in components
        task: build_component

  build_component:
    requires: [component]
    steps:
      - run: 'echo "Building component: ${{ component }}"'

How It Works

  1. for: in a step - defines the loop with for: variable in collection
  2. task: in the same step - names the task to invoke for each iteration
  3. Loop variable - becomes available in the invoked task as ${{ variable }}
  4. requires: - the invoked task can declare required variables to validate they are present

Missing Variables

If a required variable is missing, execution fails with a clear error:

  job 'deploy_service' requires variables [env service_version] but missing: [env]

See Also

  • Steps - Step configuration
  • Jobs - Job configuration