Scripting & automation

Drive the CLI from scripts.

The CLI is non-interactive: every input is a flag, an environment variable, or a file, and every command reports failure through its exit code.

Parameterize a job with --set

--set key=value overrides a key declared in a job's state block, so one job file covers many variations:

for region in us-east-1 us-west-2 eu-west-1; do
  tracemill run ./my-job.yaml --set region="$region"
done

Values are YAML-decoded, so --set port=8443 is an integer and --set 'users=[alice, bob]' is a list. A value can also be an expression, such as --set 'region=gen.aws_region()' — quote it, because the shell treats unquoted parentheses as syntax. The CLI reference has the full typing rules.

Machine-readable output

The list commands accept --json:

tracemill list event-types --json
tracemill list generators --json
tracemill list pools --job ./my-job.yaml --json

Events of JSON event types are written to stdout as JSONL, one event per line, so they pipe into tools such as jq. Event types with another format, such as XML Windows event logs or key-value text, are written in that format instead.

tracemill run scenarios/aws/cloudtrail/delete-trail | jq -r '.eventName'

Errors and the statistics overlay go to stderr and never mix with events on stdout.

Environment variables

TRACEMILL_LIBRARY and TRACEMILL_VERBOSE replace the --library and --verbose flags. Set them once at the top of a script instead of repeating the flags. The exception is tracemill update, which in a non-interactive shell installs to a non-default directory only when it is passed with --library.

Stopping on failure

Commands exit non-zero on any failure, so set -e (or checking $?) is enough to stop a script at the first failed validation or delivery:

set -euo pipefail
tracemill validate --dir ./content
tracemill run ./content/jobs/my-detection.yaml --dry-run