Skip to main content

Getting Started with Taskfile

1

Create your Taskfile

There are multiple ways to create a Taskfile:
  • Create a Taskfile in the current directory
  • Create a Taskfile in a specific directory
  • Create a Taskfile with a custom filename
  • Manually create a Taskfile
# Create a Taskfile.yml in the current directory
task --init

# Create a Taskfile.yml in the specified directory (must exist)
task --init ./directory-path

# Create a custom Taskfile
task --init CustomTaskfile.yml

# Manually create a Taskfile
touch Taskfile.yml
2

Open the Taskfile in your editor

The generated Taskfile will look like this:
Taskfile.yml
version: '3'

vars:
  GREETING: Hello, World!

tasks:
  default:
    cmds:
      - echo "{{.GREETING}}"
    silent: true
Here is a breakdown of the fields:
FieldDescription
versionThe version of the Taskfile format to run
varsVariables that can be used in the Taskfile
tasksThe tasks to run
cmdsThe commands to run
silentIf true, task metadata will not be printed — only the command output
The task name in this example is default. You can define more tasks by adding them to the tasks section.
3

Add a new task

Taskfile.yml
version: '3'

vars:
  GREETING: Hello, World!

tasks:
  default:
    cmds:
      - echo "{{.GREETING}}"
    silent: true
  hello:
    cmds:
      - echo 'Hello World from Task!' > output.txt
4

Run the task

Use task --help to see all available options and flags.
When you run the task command, it looks for a Taskfile in the current directory or in the specified directory.
# Run a task by name
task <task-name>

# Run the task in the current directory
task default

# Run the task in a specified directory
task --dir ./directory-path default

# Run the task with a custom Taskfile
task --taskfile CustomTaskfile.yml default
To run the hello task:
task hello
5

Verify the output

Check the contents of output.txt:
cat output.txt
You should see:
Hello World from Task!

Build docs developers (and LLMs) love