Skip to content

System environment variables wont be applied on task vars if a default env is already configured #2644

@pschirch

Description

@pschirch

Description

Hey,

we stumbled upon a strange environment variable mapping issue. To explain it, we create a minimal example.

There is one task called build that calls a CLI from a specific tool. The name of the cli task can be configured by an environment variable called CLI. By default this is configured to tool.

version: '3'

env:
  CLI: tool

tasks:
  build:
    cmds:
      - task: '{{ .CLI }}'

  tool:
    cmds:
      - echo "Running CLI [${CLI}] in standard mode"

  tool:ci:
    cmds:
      - echo "Running CLI [${CLI}] in CI mode"

If you run task build, the default CLI runs correctly.

task build
task: [tool] echo "Running CLI [${CLI}] in standard mode"
Running CLI [tool] in standard mode

Now you want to run the same build with another preconfigured CLI. To reach that, you should configure CLI to tool:ci in your pipeline. But unfortunately, task still use the default value configured in Taskfile.yml.

CLI=tool:ci task build 
task: [tool] echo "Running CLI [${CLI}] in standard mode"
Running CLI [tool:ci] in standard mode

If you comment out the default value from Taskfile.yml, it works.

CLI=tool:ci task build
task: [tool:ci] echo "Running CLI [${CLI}] in CI mode"
Running CLI [tool:ci] in CI mode

Additionally, if configure CLI as an argument for task while the default value is commented out, the right CLI is getting called, but the environment variable is missing in the task context.

task build CLI=tool:ci           
task: [tool:ci] echo "Running CLI [${CLI}] in CI mode"
Running CLI [] in CI mode

If the default value for CLI is configured in Taskfile.yml the .CLI variable in the build task is getting initialized with that value, but system environment variables with the same name will be ignored, but should be consumed, even there is already an default.

Maybe that is a precedence issue?

Using Go Template function default for default values is not an appreciate solution here.

Any advice?

Version

3.46.4

Operating system

Linux (Ubuntu 24.04)

Experiments Enabled

No response

Example Taskfile

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions