Loops

Use for: in steps to invoke tasks or run commands 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 }}"'

List Loop Nested Loop Matrix Loop Matrix (Multi-Iterator)

How It Works

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

Multi-Iterator (Matrix)

Use a list of iterators to create a cartesian product (all combinations):

  steps:
  - for:
      - goos in ["linux", "darwin"]
      - goarch in ["amd64", "arm64"]
    run: echo "Building ${{ goos }}-${{ goarch }}"

This produces 4 iterations: linux-amd64 , linux-arm64 , darwin-amd64 , darwin-arm64 .

This is similar to GitHub Actions' matrix strategy, but more flexible:

  • Variables are defined inline or from pipeline vars
  • No separate strategy block needed
  • Works with any step type (run: , task: , cmd: )

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