task
task copied to clipboard
When calling a subtask, the passed variable cannot directly overwrite the value in the subtask, which is inconsistent with the document description.
If use the template default method, cannot use shell commands to obtain the default value.
Hi, this is because point 1 (variables declared in the task definition) has precedence. You can use the default function in something like this:
build:
vars:
PARAM: '{{ .PARAM | default "foo" }}'
GOARCH_DEFAULT: { sh: go env GOARCH }
GOARCH: '{{ .GOARCH | default .GOARCH_DEFAULT }}'
cmds:
- echo {{.GOARCH}} {{.PARAM}}
In case of GOARCH, you would need a helper variable, because this cannot be combined with sh:.
Yes, you need to use default function