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

env var templating is inconsistent with description in docs #1977

Closed
nathanperkins opened this issue Dec 30, 2024 · 0 comments
Closed

env var templating is inconsistent with description in docs #1977

nathanperkins opened this issue Dec 30, 2024 · 0 comments

Comments

@nathanperkins
Copy link

nathanperkins commented Dec 30, 2024

Description

The docs specify this ordering:

Variables can be set in many places in a Taskfile. When executing templates, Task will look for variables in the order listed below (most important first):

  • Variables declared in the task definition
  • Variables given while calling a task from another (See Calling another task above)
  • Variables of the included Taskfile (when the task is included)
  • Variables of the inclusion of the Taskfile (when the task is included)
  • Global variables (those declared in the vars: option in the Taskfile)
  • Environment variables

Despite the fact that Environment variables are listed with the lowest priority in the docs, it seems that they are taking the highest priority over Variables declared in the task definition and Variables given while calling a task from another.

It seems like the templating within the env block has a completely different ordering, which is not shown in the docs.

This is making it difficult for me to define tasks with a static set of variables that are not overridden by the local environment. I want to do this so I can have tasks which perform operations on a specific cluster, even when run in a local env which has envvars or dotfiles pointing to a different cluster.

Version

v3.38.0

Operating system

Linux

Experiments Enabled

No response

Example Taskfile

version: "3.38.0"

tasks:
  foo:
    requires:
      vars:
        - FOO
    env:
      FOO: "{{.FOO}}"
    cmd: echo $FOO

  bar:
    cmd:
      task: foo
      vars:
        FOO: bar

  baz:
    vars:
      FOO: foo
    env:
      FOO: "{{.FOO}}"
    cmd: echo ${FOO}

Example Outputs

Without an env vars set, I see:

$ task foo
task: Task "foo" cancelled because it is missing required variables: FOO

$ task bar
task: [foo] echo $FOO
bar

$ task baz
task: [baz] echo ${FOO}
foo

With an env var set, I see:

$ FOO=moo task foo
task: [foo] echo $FOO
moo

$ FOO=moo task bar
task: [foo] echo $FOO
moo

$ FOO=moo task baz
task: [baz] echo ${FOO}
moo
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Dec 30, 2024
@task-bot task-bot removed the state: needs triage Waiting to be triaged by a maintainer. label Dec 30, 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

2 participants