Variables
How to use variables in Taskfile
Variable types
Taskfile supports several types of variables:
- string
- bool
- int
- float
- array
- map
Set default values for variables
Dynamic variables / Shell command output
You can use sh
to execute shell commands and use their output as variable values. This is useful for dynamic data retrieval, such as system information or environment variables.
Set required variables
You can set variables as required. If the variable is not defined, the task will not run and an error message will be displayed.
Ensure variables have allowed values
You can ensure that variables have allowed values by using the enum
field. If the variable value is not in the list of allowed values, the task will not run and an error message will be displayed.
Referencing other variables
You can reference other variables from one task to another. If you are using template engine concept, it will not able to work as expected. Here's an example.
As you can see, the output is not what we expected. So to reference variables correctly, you should use ref
keyword.
The same concept applies to deps
as well.
Parsing JSON/YAML into map variables
This only works with ref
keyword, not template engine concept.
You can parse JSON or YAML strings into map variables using the fromJson
or fromYaml
functions. This is useful for working with structured data.