Skip to main content

API Reference

CLI

Task command line tool has the following syntax:

task [--flags] [tasks...] [-- CLI_ARGS...]
tip

If -- is given, all remaning arguments will be assigned to a special CLI_ARGS variable

ShortFlagTypeDefaultDescription
-c--colorbooltrueColored output. Enabled by default. Set flag to false or use NO_COLOR=1 to disable.
-C--concurrencyint0Limit number tasks to run concurrently. Zero means unlimited.
-d--dirstringWorking directorySets directory of execution.
-n--dryboolfalseCompiles and prints tasks in the order that they would be run, without executing them.
-x--exit-codeboolfalsePass-through the exit code of the task command.
-f--forceboolfalseForces execution even when the task is up-to-date.
-h--helpboolfalseShows Task usage.
-i--initboolfalseCreates a new Taskfile.yaml in the current folder.
-l--listboolfalseLists tasks with description of current Taskfile.
-a--list-allboolfalseLists tasks with or without a description.
-o--outputstringDefault set in the Taskfile or intervealedSets output style: [interleaved/group/prefixed].
--output-group-beginstringMessage template to print before a task's grouped output.
--output-group-end stringMessage template to print after a task's grouped output.
-p--parallelboolfalseExecutes tasks provided on command line in parallel.
-s--silentboolfalseDisables echoing.
--statusboolfalseExits with non-zero exit code if any of the given tasks is not up-to-date.
--summaryboolfalseShow summary about a task.
-t--taskfilestringTaskfile.yml or Taskfile.yaml
-v--verboseboolfalseEnables verbose mode.
--versionboolfalseShow Task version.
-w--watchboolfalseEnables watch of the given task.

Special Variables

There are some special variables that is available on the templating system:

VarDescription
CLI_ARGSContain all extra arguments passed after -- when calling Task through the CLI.
TASKThe name of the current task.
ROOT_DIRThe absolute path of the root Taskfile.
TASKFILE_DIRThe absolute path of the included Taskfile.
CHECKSUMThe checksum of the files listed in sources. Only available within the status prop and if method is set to checksum.
TIMESTAMPThe date object of the greatest timestamp of the files listes in sources. Only available within the status prop and if method is set to timestamp.

ENV

Some environment variables can be overriden to adjust Task behavior.

ENVDefaultDescription
TASK_TEMP_DIR.taskLocation of the temp dir. Can relative to the project like tmp/task or absolute like /tmp/.task or ~/.task.
TASK_COLOR_RESET0Color used for white.
TASK_COLOR_BLUE34Color used for blue.
TASK_COLOR_GREEN32Color used for green.
TASK_COLOR_CYAN36Color used for cyan.
TASK_COLOR_YELLOW33Color used for yellow.
TASK_COLOR_MAGENTA35Color used for magenta.
TASK_COLOR_RED31Color used for red.

Schema

Taskfile

AttributeTypeDefaultDescription
versionstringVersion of the Taskfile. The current version is 3.
includesmap[string]IncludeAdditional Taskfiles to be included.
outputstringinterleavedOutput mode. Available options: interleaved, group and prefixed.
methodstringchecksumDefault method in this Taskfile. Can be overriden in a task by task basis. Available options: checksum, timestamp and none.
silentboolfalseDefault "silent" options for this Taskfile. If false, can be overidden with true in a task by task basis.
runstringalwaysDefault "run" option for this Taskfile. Available options: always, once and when_changed.
varsmap[string]VariableGlobal variables.
envmap[string]VariableGlobal environment.
dotenv[]stringA list of .env file paths to be parsed.
tasksmap[string]TaskThe task definitions.

Include

AttributeTypeDefaultDescription
taskfilestringThe path for the Taskfile or directory to be included. If a directory, Task will look for files named Taskfile.yml or Taskfile.yaml inside that directory. If a relative path, resolved relative to the directory containing the including Taskfile.
dirstringThe parent Taskfile directoryThe working directory of the included tasks when run.
optionalboolfalseIf true, no errors will be thrown if the specified file does not exist.
internalboolfalseIf true, tasks will be omitted from both --list and --list-all.
info

Informing only a string like below is equivalent to setting that value to the taskfile attribute.

includes:
foo: ./path

Task

AttributeTypeDefaultDescription
descstringA short description of the task. This is listed when calling task --list.
summarystringA longer description of the task. This is listed when calling task --summary [task].
sources[]stringList of sources to check before running this task. Relevant for checksum and timestamp methods. Can be file paths or star globs.
dirstringThe current directory which this task should run.
methodstringchecksumMethod used by this task. Default to the one declared globally or checksum. Available options: checksum, timestamp and none
silentboolfalseSkips some output for this task. Note that STDOUT and STDERR of the commands will still be redirected.
internalboolfalseIf true, omit this task from both --list and --list-all.
runstringThe one declared globally in the Taskfile or alwaysSpecifies whether the task should run again or not if called more than once. Available options: always, once and when_changed.
prefixstringAllows to override the prefix print before the STDOUT. Only relevant when using the prefixed output mode.
ignore_errorboolfalseContinue execution if errors happen while executing the commands.
generates[]stringList of files meant to be generated by this task. Relevant for timestamp method. Can be file paths or star globs.
status[]stringList of commands to check if this task should run. The task is skipped otherwise. This overrides method, sources and generates.
preconditions[]PreconditionList of commands to check if this task should run. The task errors otherwise.
varsmap[string]VariableTask variables.
envmap[string]VariableTask environment.
deps[]DependencyList of dependencies of this task.
cmds[]CommandList of commands to be executed.
info

These alternative syntaxes are available. They will set the given values to cmds and everything else will be set to their default values:

tasks:
foo: echo "foo"

foobar:
- echo "foo"
- echo "bar"

baz:
cmd: echo "baz"

Dependency

AttributeTypeDefaultDescription
taskstringThe task to be execute as a dependency.
varsmap[string]VariableOptional additional variables to be passed to this task.
tip

If you don't want to set additional variables, it's enough to declare the dependency as a list of strings (they will be assigned to task):

tasks:
foo:
deps: [foo, bar]

Command

AttributeTypeDefaultDescription
cmdstringThe shell command to be executed.
deferstringAlternative to cmd, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together with cmd.
silentboolfalseSkips some output for this command. Note that STDOUT and STDERR of the commands will still be redirected.
ignore_errorboolfalseContinue execution if errors happen while executing the command.
taskstringSet this to trigger execution of another task instead of running a command. This cannot be set together with cmd.
varsmap[string]VariableOptional additional variables to be passed to the referenced task. Only relevant when setting task instead of cmd.
info

If given as a a string, the value will be assigned to cmd:

tasks:
foo:
cmds:
- echo "foo"
- echo "bar"

Variable

AttributeTypeDefaultDescription
itselfstringA static value that will be set to the variable.
shstringA shell command. The output (STDOUT) will be assigned to the variable.
info

Static and dynamic variables have different syntaxes, like below:

vars:
STATIC: static
DYNAMIC:
sh: echo "dynamic"

Precondition

AttributeTypeDefaultDescription
shstringCommand to be executed. If a non-zero exit code is returned, the task errors without executing its commands.
msgstringOptional message to print if the precondition isn't met.
tip

If you don't want to set a different message, you can declare a precondition like this and the value will be assigned to sh:

tasks:
foo:
precondition: test -f Taskfile.yml