Running Taskfile
Learn how to run a Taskfile.
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.yml
taskfile.yml
Taskfile.yaml
taskfile.yaml
Taskfile.dist.yml
taskfile.dist.yml
Taskfile.dist.yaml
taskfile.dist.yaml
Run a Taskfile from a subdirectory
Let's said we're in the sub-directory
, but the Taskfile.yml
cannot be found in the current directory, in this case, when you run the task
command, it will go up one directory level to look for the Taskfile until it finds one or reaches the root directory.
In this case, it will still work if you run the task
command from the sub-directory
.
Special {{ .USER_WORKING_DIR }}
variable
{{ .USER_WORKING_DIR }}
is a special variable that contains the path to the directory where the task
commadn was run. For example, we can cd
into the sub-directory
and run a task
command to build a Docker image or display Dockerfile
content without having to specify the full path and can remove duplicate Taskfiles with the same content.
We just need to make sure the sub-directory
contains the Dockerfile
, then it will be working as expected.
Run a global Taskfile
You can run a global Taskfile by specifing the -g
or --global
option. This will look for a Taskfile in the user's home directory.
/home/<username>/Taskfile.yml
C:/Users/<username>/Taskfile.yml
Read a Taskfile from stdin
This method is very useful when you are generating Taskfile content dynamically or when you want to run a Taskfile without saving it to a file. To read a Taskfile from stdin, you have to specify two things:
-t
or--taskfile
option-
pipe
- This
Taskfile
path must correctly point to the Taskfile content.