Description
Description
Requires does not check if a variable is set, it only checks is a variable is "present". As a result, variables which are set to "null/nil" will pass the required check.
Version
3.43.2
Operating system
Linux (WSL)
Experiments Enabled
No response
Example Taskfile
version: '3'
tasks:
default:
vars:
A: null
B: '{{.B}}'
env:
A: '{{.A}}'
B: '{{.B}}'
C: '{{.C}}'
cmds:
- echo "$A"
- echo "$B"
- echo "$C"
requires:
#vars: [A, B, C]
vars: [A, B]
Example output:
$ task
task: [default] echo "$A"
task: [default] echo "$B"
task: [default] echo "$C"
Obviously, none of the variables are set. Swap the comment line on the requires constraint to observe the behavior change.
The related code is here:
Line 17 in a459eea
... where it is observed that the content of variables is not checked. I have read though the PR for this feature and did not notice any conversation about this scenario. I think the documentation explains the expectation correctly:
List of variable or environment variable names that must be set if this task is to execute and run[period missing]
I appreciate that setting a variable to nil can be considered as being set ... but with how templating works in Task, I think set means set to something other than . For example here there is no difference when A is not set, or set to nil ... the default condition will be taken:
A: '{{.A | default "A"}}'