command, args, env, inputs, and outputs when configuring a task. They provide a way of accessing file group paths, referencing values from other task fields, and referencing metadata about the project and task itself.
Functions
A token function is labeled as such because it takes a single argument, starts with an@, and is formatted as @name(arg). Token functions expand to file paths, globs, or other values based on the function.
File groups
These functions reference file groups by name, where the name is passed as the argument.@group(name)
args, env, inputs, outputs@group(file_group) token is a standard token that will be replaced with the file group items as-is, for both file paths and globs. This token exists for reusability purposes.
moon.yml
@dirs(name)
args, env, inputs, outputs@dirs(file_group) token will be replaced with an expanded list of directory paths, derived from the file group of the same name. If a glob pattern is detected, it will aggregate all directories found.
moon.yml
@files(name)
args, env, inputs, outputs@files(file_group) token will be replaced with an expanded list of file paths, derived from the file group of the same name. If a glob pattern is detected, it will aggregate all files found.
moon.yml
@globs(name)
args, env, inputs, outputs@globs(file_group) token will be replaced with the list of glob patterns as-is, derived from the file group of the same name. If a non-glob pattern is detected, it will be ignored.
moon.yml
@root(name)
args, env, inputs, outputs@root(file_group) token will be replaced with the lowest common directory, derived from the file group of the same name. If a glob pattern is detected, it will walk the file system and aggregate all directories found before reducing.
moon.yml
When there are no directories, or too many directories at different levels, this function will return the project root using
..@envs(name)
inputs only@envs(file_group) token will be replaced with all environment variables that have been configured in the group of the provided name.
moon.yml
Inputs & outputs
@in(index)
script and args only@in(index) token will be replaced with a single path, derived from inputs by numerical index. If a glob pattern is referenced by index, the glob will be used as-is.
moon.yml
@out(index)
script and args only@out(index) token will be replaced with a single path, derived from outputs by numerical index.
moon.yml
Miscellaneous
@meta(key)
command, script, args, env@meta(key) token can be used to access project metadata and will be replaced with a value derived from project in moon.*.
Built-in fields (like name and description) are used as-is. Custom metadata defined in project can also be accessed by key.
moon.yml
Variables
A token variable is a value that starts with$ and is substituted to a value derived from the current workspace, project, and task. Unlike token functions, token variables can be placed within content when necessary, and support multiple variables within the same content.
Environment
The current host architecture, derived from the Rust ARCH constant.Examples:
x86_64, aarch64The current operating system, derived from the Rust OS constant.Examples:
linux, macos, windowsThe current operating system family, either
unix or windows.moon.yml
Workspace
The current working directory.
Absolute file path to the workspace root.
moon.yml
Project
Most values are derived from settings inmoon.*. When a setting is not defined, the variable defaults to “unknown” (for enums) or an empty string.
ID of the project that owns the currently running task.
Alias of the project that owns the currently running task.
Comma-separated list of all project aliases.
The discussion channel for the project, as defined with
project.channel.The human-readable name of the project, as defined with
project.title.The owner of the project, as defined with
project.owner.Absolute file path to the project root.
Relative file path from the workspace root to the project root.
moon.yml
Task
Fully-qualified target that is currently running (e.g.,
app:build).ID of the task that is currently running. Does not include the project ID.
The toolchain that the task will run against.
Comma-separated list of all toolchains for the task.
The type of task, based on its configured settings.
moon.yml
Date/Time
The current date in the format of
YYYY-MM-DD.The current date and time in the format of
YYYY-MM-DD_HH:MM:SS.The current time in the format of
HH:MM:SS.The current date and time as a UNIX timestamp in seconds.
moon.yml
VCS
The current branch.
The repository slug, in the format of
owner/repo.The current revision (commit hash, etc).
moon.yml
Token expansion
Tokens are expanded during task execution through theTokenExpander which:
- Scans the task configuration - Identifies all tokens in command, args, env, inputs, and outputs
- Validates token usage - Ensures tokens are used in valid scopes
- Expands functions - Replaces function tokens with their expanded values
- Substitutes variables - Replaces variable tokens with their actual values
- Resolves paths - Converts relative paths to appropriate formats based on task settings
Scope validation
Different tokens are valid in different contexts:- Command scope - Only certain variables allowed
- Args scope - Functions and variables allowed
- Env scope - Functions and variables allowed
- Inputs scope - File group functions and specific tokens
- Outputs scope - File group functions and specific tokens
Path resolution
When tokens expand to file paths, they are resolved based on:- Task’s
runFromWorkspaceRootsetting - Determines if paths are relative to workspace or project - Operating system - Adjusts path separators and formats
- Negated globs - Preserves
!prefix for exclusion patterns
Related
- File groups - Define reusable file sets
- Tasks - Configure tasks
- Token expander source - Implementation details