Skip to content
Latchkey

just: Variables and Assignments in a justfile

just variables are declared with := and interpolated into recipes with {{ }}.

Variables let you name a version or path once and reuse it across recipes. just evaluates assignments at parse time, so values are available everywhere in the file.

What it does

A just variable is declared with name := value at the top level of the justfile. Inside recipe lines you reference it with {{ name }}. Values can be string literals, the result of backtick command substitution, or built-in functions like env_var().

Common usage

justfile
# justfile
version := "1.2.3"
image := "registry.example.com/app:" + version
commit := `git rev-parse --short HEAD`

build:
    docker build -t {{image}} .
    echo "built {{image}} at {{commit}}"

Syntax

FormWhat it does
name := "value"Assign a variable (evaluated at parse time)
{{ name }}Interpolate a variable into a recipe line
name := commandAssign the output of a shell command
export name := "value"Also export the variable to recipe environments
name := env_var("VAR")Read a required environment variable
name := env_var_or_default("VAR", "x")Read an env var with a fallback

In CI

Use env_var_or_default() for values a pipeline may or may not set, so a missing variable degrades gracefully instead of failing the parse. Override a variable from the command line with just VAR=value <recipe>, which CI steps use to inject build numbers.

Common errors in CI

"error: Variable X not defined" means you interpolated {{X}} without declaring it. "error: Call to function env_var failed: environment variable VAR not present" means env_var() hit an unset variable; switch to env_var_or_default(). Backtick assignments fail the whole parse if the command exits non-zero, so guard them.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →