Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot execute task for each item in a list #1485

Closed
jakubledl opened this issue Jan 26, 2024 · 1 comment
Closed

Cannot execute task for each item in a list #1485

jakubledl opened this issue Jan 26, 2024 · 1 comment

Comments

@jakubledl
Copy link

  • Task version: Task version: 3.33.1 (installed via homebrew)
  • Operating system: macos 14.2.1
  • Experiments enabled: none

Following the documentation sample at https://taskfile.dev/usage/#looping-over-tasks.

Given the following Taskfile.yml:

version: 3

tasks:
  install-bins:
    cmds:
      - for:
          - google.golang.org/protobuf/cmd/protoc-gen-go
          - google.golang.org/grpc/cmd/protoc-gen-go-grpc
        task: install-bin
        # cmd: echo {{.ITEM}}
        vars:
          BIN: {{.ITEM}}

  install-bin:
    internal: true
    cmds:
      - echo {{.BIN}}

running task install-bins gives the following:

task: Failed to parse Taskfile.yml:
yaml: line 6: invalid keys in command
[1]    8230 exit 102   task install-bins

Modyfing the file as follows (not touching line 6 at all):

version: 3

tasks:
  install-bins:
    cmds:
      - for:
          - google.golang.org/protobuf/cmd/protoc-gen-go
          - google.golang.org/grpc/cmd/protoc-gen-go-grpc
        # task: install-bin
        cmd: echo {{.ITEM}}
        vars:
          BIN: {{.ITEM}}

  install-bin:
    internal: true
    cmds:
      - echo {{.BIN}}

gives the expected result:

task: [install-bins] echo google.golang.org/protobuf/cmd/protoc-gen-go
google.golang.org/protobuf/cmd/protoc-gen-go
task: [install-bins] echo google.golang.org/grpc/cmd/protoc-gen-go-grpc
google.golang.org/grpc/cmd/protoc-gen-go-grpc
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Jan 26, 2024
@pd93
Copy link
Member

pd93 commented Jan 26, 2024

Hi @jakubledl. Looks like a quotation issue to me. YAML is sensitive to strings when values begin or contain certain characters. In general, it's best to quote them to stop this issue:

version: 3

tasks:
  install-bins:
    cmds:
      - for:
          - google.golang.org/protobuf/cmd/protoc-gen-go
          - google.golang.org/grpc/cmd/protoc-gen-go-grpc
        task: install-bin
        vars:
          BIN: "{{.ITEM}}" # <-- Quoting this value fixes the issue

  install-bin:
    internal: true
    cmds:
      - echo {{.BIN}}

There is some more detailed information on YAML strings and when you should quote them in this StackOverflow post.

@pd93 pd93 closed this as completed Jan 26, 2024
@task-bot task-bot removed the state: needs triage Waiting to be triaged by a maintainer. label Jan 26, 2024
@pd93 pd93 added the type: question Further information is requested. label Jan 26, 2024
@pd93 pd93 removed the type: question Further information is requested. label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants