Skip to content

for loop cannot iterate over complex variables from included Taskfiles #2606

@michaelprujan

Description

@michaelprujan

Description

When using for loop with a variable defined in an included Taskfile, the variable is empty/not accessible. This applies to complex variables (list of objects).

Taskfile.yml

`version: "3"

includes:
  proc: ./proc_task.yml

tasks:
  features-sample-run:
    for:
      var: PROCESS_FEATURES
    cmd: |
      echo "Processing feature {{.ITEM.id}}"
      {{if .ITEM.macros}}echo "  Macros: {{.ITEM.macros}}"{{end}}`

proc_task.yml

`version: "3"

vars:
  PROCESS_FEATURES:
    - id: 1
    - id: 2
      macros: -DUW_RINGBUF
    - id: 3
      macros: -DUW_RINGBUF -DUW_FENTRY

Output

$ task features-sample-run
task: [features-sample-run] echo "Processing feature "
Processing feature

Expected behavior

The for loop should iterate over the PROCESS_FEATURES list and output:

Processing feature 1
Processing feature 2
  Macros: -DUW_RINGBUF
Processing feature 3
  Macros: -DUW_RINGBUF -DUW_FENTRY

What I tried

  • for: { var: PROCESS_FEATURES } — empty
  • for: { var: proc.PROCESS_FEATURES } — empty
  • Using vars: FEATURES: '{{.proc.PROCESS_FEATURES}}' then for: { var: FEATURES } — empty

Related issues

Version

$ task --version

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: loopsChanges related to looping over tasks/commands.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions