task command is used to run a Taskfile. By default, it looks for one of the supported Taskfile names in the current directory. You can also specify a Taskfile explicitly using the -t or --taskfile option.
Supported Taskfile Names
Taskfile.ymltaskfile.ymlTaskfile.yamltaskfile.yamlTaskfile.dist.ymltaskfile.dist.ymlTaskfile.dist.yamltaskfile.dist.yaml
Run a Taskfile from a Subdirectory
If you are in a subdirectory where noTaskfile.yml exists, running the task command will traverse up the directory tree until it finds a Taskfile or reaches the root.
Given this structure:
task from inside sub-directory still works:
Demo and output
Special {{ .USER_WORKING_DIR }} Variable
{{ .USER_WORKING_DIR }} is a special variable containing the path to the directory where the task command was run. This lets you run tasks like building a Docker image from any subdirectory without duplicating Taskfiles.
Make sure the subdirectory you
cd into contains the expected files (e.g., a Dockerfile) for the task to work correctly.Taskfile.yml
Demo and output
Run a Global Taskfile
Use the-g or --global flag to run a Taskfile from the user’s home directory:
/home/<username>/Taskfile.ymlC:/Users/<username>/Taskfile.yml
~/Taskfile.yml
Demo and output
Read a Taskfile from stdin
This method is useful when generating Taskfile content dynamically or running a Taskfile without saving it to disk. Specify both the-t flag and a - pipe:
Demo and output