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

Feature request: Allow specifying env vars at the command level #1550

Open
justinrixx opened this issue Mar 12, 2024 · 2 comments
Open

Feature request: Allow specifying env vars at the command level #1550

justinrixx opened this issue Mar 12, 2024 · 2 comments
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@justinrixx
Copy link

justinrixx commented Mar 12, 2024

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
    ...
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Mar 12, 2024
@noble-varghese
Copy link

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.

@trulede
Copy link

trulede commented May 21, 2024

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)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

4 participants