Skip to content

Tasks

Task recipes always run when invoked. Use them for commands that should execute every time.

task clean:
rm -rf dist/
rm -rf node_modules/
task test:
npm test
task dev:
npm run dev

Tasks support parameters with optional default values:

task greet name="World":
echo "Hello, {{name}}!"
task deploy env="staging" version="latest":
echo "Deploying {{version}} to {{env}}"
./deploy.sh {{env}} {{version}}
Terminal window
$ jake greet name=Alice
Hello, Alice!
$ jake deploy env=production version=1.2.3
Deploying 1.2.3 to production

Tasks can depend on other recipes:

task build:
echo "Building..."
task test: [build]
echo "Testing after build..."
task deploy: [build, test]
echo "Deploying after build and test..."

Pass arguments directly using {{$1}}, {{$2}}, etc:

task greet:
echo "Hello, {{$1}}!"
Terminal window
$ jake greet World
Hello, World!

Access all arguments with {{$@}}:

task echo-all:
echo "Arguments: {{$@}}"
Terminal window
$ jake echo-all a b c d
Arguments: a b c d
task deploy:
@description "Deploy application to production server"
./deploy.sh
@group build
task build-frontend:
npm run build
@group build
task build-backend:
cargo build
@only-os linux macos
task install-deps:
./install.sh
@only-os windows
task install-deps:
install.bat

Valid OS values: linux, macos, windows

Use task when:

  • The command should run every time (tests, dev servers, deployments)
  • You need parameters
  • You want explicit, self-documenting syntax

Use file when:

  • The recipe produces an output file
  • You want incremental builds