moon run <target> command, which requires a target - the pairing of a scope and task name.
Basic Task Execution
To run a task, use the format<project>:<task>:
appis the project namebuildis the task nameapp:buildis the target
What Happens When You Run a Task
When you executemoon run, the following happens:
Execute in parallel
All tasks in the graph run in parallel and in topological order (dependency chain).
Running Multiple Tasks
You can run multiple tasks at once:Running Upstream Dependencies
moon always runs upstream dependencies (defined viadeps) before running the primary target, as their outputs may be required:
moon.yml
moon run app:build, moon will:
- Find all projects that
appdepends on - Run
buildin those projects first - Then run
buildinapp
Running Downstream Dependents
If you’re working on a shared library and want to verify that downstream projects haven’t been broken, use the--downstream option:
shared-lib:build- All projects that depend on
shared-liband theirbuildtasks
Running Based on Affected Files
By default,moon run always runs the target, but relies on smart hashing and caching. If you’d like to only run a target when files have actually changed, use the --affected flag:
- Extract locally changed files from your VCS (git)
- Exit early if no files intersect with the task’s
inputs - Only run tasks that are affected by the changes
Using Remote Changes
To determine affected files based on remote changes instead of local changes:HEAD against the vcs.defaultBranch configured in your workspace.
Filtering by Change Status
Filter affected files based on their change status:added- Newly created filesdeleted- Removed filesmodified- Changed filesstaged- Files in git staging areaunstaged- Modified but not staged filesuntracked- Files not tracked by git
Passing Arguments to Commands
To pass additional arguments to the underlying task command beyond the definedargs, use -- followed by your arguments:
The
-- delimiter and any arguments must be defined last on the command line.Advanced Run Targeting
moon provides powerful targeting capabilities for advanced workflows:Run a Task in All Projects
Omit the project name to run a task across all projects:build task in every project that defines it.
Run Tasks Based on Queries
Use the--query option to filter projects:
Run Tasks Based on Tags
If your projects define tags, you can target them:Run in Affected Projects Only
Combine:build with --affected to run only in affected projects:
Common Run Patterns
Here are some common patterns:CI/CD Usage
In continuous integration, you typically want to only run tasks for affected projects:- Compare against the default branch (e.g.,
main) - Only run tasks in projects with modified or added files
- Leverage the dependency graph to ensure dependencies are built first
- Use remote caching to speed up builds
Task Output
When running tasks, moon provides detailed output:cached- Task was cached and not re-run(2.3s)- Task execution time- Progress indicators show running status
Verbose Output
For more detailed output, use the--log flag:
error- Only errorswarn- Warnings and errorsinfo- General information (default)debug- Detailed debug informationtrace- Very verbose trace information
Next Steps
moon run Reference
Complete reference for the moon run command
Task Concepts
Learn more about how tasks work in moon
Caching
Understanding moon’s smart caching system
CI/CD Setup
Configure moon for continuous integration