-
-
Notifications
You must be signed in to change notification settings - Fork 554
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
Unable to override vars at task level #888
Comments
@ssbarnea when you're calling the version: "3"
vars:
FOO: global-foo
tasks:
default:
vars:
FOO: default-foo
cmds:
- task: subtask
vars:
FOO: "{{.FOO}}"
subtask:
vars:
FOO: '{{.FOO | default "subtask-foo"}}'
cmds:
- echo {{.FOO}} In this example |
I came here looking for an answer to a similar puzzle I have. I have this version: '3'
tasks:
hello:
desc: Print "Hello World!"
cmds:
- echo "Hello {{ .NAME }}!"
vars:
NAME: World I expect to be able to override the variable $ task hello NAME=James
task: [hello] echo "Hello World!"
Hello World! But sadly this does not seem to work 😢 |
@andreynering I think we're missing a subtle point here. It seems only possible to override variables declared globally and not at a task level. This is counter intuitive to me 😢 The following example version: '3'
vars:
NAME: "World"
tasks:
hello:
desc: Print "Hello World!"
cmds:
- echo "Hello {{ .NAME }} !"
vars:
NAME: '{{ .NAME | default "World" }}' $ task hello
task: [hello] echo "Hello World !"
Hello World !
$ task hello NAME=James
task: [hello] echo "Hello James !"
Hello James ! But the following does not: version: '3'
tasks:
hello:
desc: Print "Hello World!"
cmds:
- echo "Hello {{ .NAME }} !"
vars:
NAME: 'World' Yes you can do what has been suggested as (IMO) work-arounds here, but IMO the title of the issue still remains. It is not possible to override a task-level variable (only a global). |
@prologic I understand what you mean, but changing that behavior now would cause side-effects and can be considered a breaking/backwards-incompatible change. In another words, it was intentionally implemented this way so the task has the control of its variables, and there are Taskfiles out there depending on this behavior. Discussions for any changes in the would be for the (far in the future) next major release. |
Okay fair enough 👌 Can we please document this though in the Documentation section on Usage -> Variables? 🤔 I spent several hours on this myself trying to understand why this wasn't working for me (something I"m used to being able to do from |
Example Taskfile showing the issue
Despite that the documentation suggests that there are 3 ways to override the vars, apparently none work for task leve, and we cannot even see one example of variable overriding inside the main test file from https://github.com/go-task/task/blob/master/testdata/vars/v3/Taskfile.yml -- all the vars are uniquely defined inside the file, which means that the overriding order is not tested by it.
We have at least these levels of vars:
My expectation is that
passed
>command
>task
>global
, but apparently I was not able to make thecommand
level to work.Temporary I could probably make use of YAML anchors in order to force taskfile to "inherit" the vars from the task level, still this should not be needed.
The text was updated successfully, but these errors were encountered: