Skip to content

Variables and secrets

Set a value once and use it in every step. Keep passwords and tokens out of your files.

env sets environment variables for a step’s command. You can put it at four levels; the nearest level wins:

# truss.yaml: every flow of the project
env:
REGION: eu
.truss/flows/deploy.yaml
env: # every step of this flow
STAGE: staging
jobs:
release:
env: # every step of this job
RETRIES: 3
steps:
- id: push
env: # this step only
STAGE: prod
run: ./push.sh "$REGION" "$STAGE"

Values are text: RETRIES: 3 sets the string 3. Do not put secrets in env; the file is plain text.

A value in env, and a dir or workdir, can use other variables:

truss.yaml
env:
DATA: ${HOME}/photo-data
.truss/flows/sort.yaml
env:
INBOX: ${DATA}/inbox # from the project
PATH: ${TRUSS_PROJECT_DIR}/bin:${PATH} # adds to your PATH
steps:
- id: sort
dir: ${INBOX}
run: sort-photos
  • TRUSS replaces ${NAME} before the step starts, the same way on every system. A variable that is not set gives an empty text; a dir that uses an unset variable fails the step.
  • $$ is a literal $. A single $ is left for the shell ($HOME).
  • Inside the run command, quote variables as your shell needs: cd "$INBOX".

Every step gets these, however the run started:

Variable Value
TRUSS_FLOW, TRUSS_JOB, TRUSS_STEP where the step is
TRUSS_RUN_ID, TRUSS_TRIGGER, TRUSS_ATTEMPT which run, why it started, and which try
TRUSS_PROJECT_DIR the project folder
TRUSS_TEMP_DIR a folder for this run only; removed when the run ends
TRUSS_DATA_DIR, TRUSS_CACHE_DIR folders that stay between runs
TRUSS_OS, TRUSS_ARCH linux, darwin or windows; amd64 or arm64
TRUSS_CHANGED_FILES for a file hook: the list of changed paths

A file cannot set these, except TRUSS_DATA_DIR and TRUSS_CACHE_DIR. Details are in the variables reference.

A secret is stored once on your machine and handed only to the steps that ask for it.

$ truss secret set NPM_TOKEN # asked twice, nothing is shown
$ truss secret list # names only, never values
steps:
- id: publish
secrets: [NPM_TOKEN] # this step gets $NPM_TOKEN
run: npm publish
  • secrets works at the top of the file, on a job and on a step.
  • A secret that is not stored fails the run before any step starts, and the error names it.
  • In the log, the value of every stored secret is replaced by *** (when the flow uses secrets). That is exact text matching: a step that encodes, splits or writes the value elsewhere is not covered. Do not print secrets, and do not run env or set -x in a step that has them.
  • The store is a file, secrets.json, in your TRUSS home (~/.truss). Only you can read it on Linux and macOS; on Windows it has the permissions of your user profile. It is not encrypted.

Each step is its own process, so export in one step does not reach the next. Write the value to a file in $TRUSS_TEMP_DIR (kept for one run) or $TRUSS_DATA_DIR (kept between runs):

steps:
- id: version
run: git describe --tags > "$TRUSS_TEMP_DIR/version"
- id: build
needs: [version]
run: go build -ldflags "-X main.v=$(cat "$TRUSS_TEMP_DIR/version")" ./...
$ truss flows show deploy push # every variable, where it comes from, set or missing
$ truss run deploy --step push --env STAGE=test

--env sets a variable exactly as given. A value built from other variables is not worked out again, so set the variable the step reads (INBOX, not DATA). Debug a flow shows this in full.

From weakest to strongest: the environment TRUSS started in, the built-in variables, truss.yaml env, flow env, job env, step env, --env on the command line, then secrets.