Skip to content

Variables

name = "Jake";
version = "1.0.0";
build_dir = "dist";

Use {{variable}} syntax in commands:

greeting = "Hello"
target = "World"
task greet:
echo "{{greeting}}, {{target}}!"

Output: Hello, World!

Variables are global and available to all recipes:

project = "myapp"
task build:
echo "Building {{project}}"
task test:
echo "Testing {{project}}"

When the same variable name is defined in multiple places, the following precedence applies (highest to lowest):

  1. Recipe parameters (passed via CLI: jake build env=prod)
  2. Environment variables (loaded via @dotenv or from shell)
  3. Jakefile variables (defined with = assignment)

This means @dotenv should appear before variable assignments to allow .env files to override defaults:

@dotenv # Load .env first
PORT = "3000" # Default value (overridden by .env if PORT is set there)
task serve:
echo "Running on port {{PORT}}"

With .env containing PORT=8080, the task outputs: Running on port 8080

Without .env or if PORT is not set, it uses the default: Running on port 3000

@dotenv # Load .env
@dotenv ".env.local" # Load specific file

Files are loaded in order; later files override earlier ones.

@export NODE_ENV=production
@export DEBUG=false

Exported variables are passed to all subprocess commands.

Use $VAR or ${VAR} syntax:

task show:
echo "Node: $NODE_ENV"
echo "Debug: ${DEBUG}"
# Database settings
DATABASE_URL=postgres://localhost/myapp
DB_POOL_SIZE=10
# API Keys (use quotes for special chars)
API_KEY="abc123!@#"
# Empty values
EMPTY_VAR=
# Escape sequences
MULTILINE=line1\nline2
WINDOWS_PATH=C:\\Users\\Name

Supported escapes: \n, \t, \r, \\, \", \', \$

Validate required environment variables:

@require API_KEY DATABASE_URL
task deploy:
echo "Deploying with $API_KEY"

Jake exits with an error if any required variable is missing.