task
task copied to clipboard
Feature request: Allow specifying env vars at the command level
It would be nice to be able to specify an env
key on a command
object (docs). This specifically enables specifying env vars in a loop, but it could have other uses.
Example I'm trying to accomplish:
tasks:
ci:image:build:
desc: build a docker image for foo
cmds:
- for: ['386', 'amd64', 'arm', 'mips', 'ppc', 'riscv', 'sparc64', 'wasm']
task: go:ci:build
env: # NOT ALLOWED
GOARCH: {{ .ITEM }}
vars:
APP_ID: foo
GO_BUILD_PACKAGE: ./cmd/foo
TEAM_ID: justinr
GO_ENV_VARS: |-
GOARCH
Instead I have to do something like this:
tasks:
ci:image:build:386:
desc: build a docker image for foo on 386
env:
GOARCH: 386
cmds:
- task: go:ci:build
vars:
APP_ID: foo
GO_BUILD_PACKAGE: ./cmd/foo
TEAM_ID: justinr
GO_ENV_VARS: |-
GOARCH
ci:image:build:amd64:
desc: build a docker image for foo on amd64
env:
GOARCH: amd64
cmds:
- task: go:ci:build
vars:
APP_ID: foo
GO_BUILD_PACKAGE: ./cmd/foo
TEAM_ID: justinr
GO_ENV_VARS: |-
GOARCH
...
Are you proposing to the ability to set the env variables when a task command is run ? Cuz, even I wanted to set env variables for specific set of commands but I had to workaround by adding the export function as a command.
Can't you assign{{ .ITEM }}
to a var in the caller task, and then set the env in the called task to that provided var (i.e. in go:ci:build)?