Variables and secrets
Set a value once and use it in every step. Keep passwords and tokens out of your files.
1. Set a variable
Section titled “1. Set a variable”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 projectenv: REGION: euenv: # every step of this flow STAGE: stagingjobs: 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.
2. Build a value from another: ${NAME}
Section titled “2. Build a value from another: ${NAME}”A value in env, and a dir or workdir, can use other variables:
env: DATA: ${HOME}/photo-dataenv: INBOX: ${DATA}/inbox # from the project PATH: ${TRUSS_PROJECT_DIR}/bin:${PATH} # adds to your PATHsteps: - 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; adirthat uses an unset variable fails the step. $$is a literal$. A single$is left for the shell ($HOME).- Inside the
runcommand, quote variables as your shell needs:cd "$INBOX".
3. What TRUSS sets for you
Section titled “3. What TRUSS sets for you”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.
4. Use a secret
Section titled “4. Use a secret”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 valuessteps: - id: publish secrets: [NPM_TOKEN] # this step gets $NPM_TOKEN run: npm publishsecretsworks 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 runenvorset -xin 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.
5. Pass a value from one step to the next
Section titled “5. Pass a value from one step to the next”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")" ./...6. See what a step gets
Section titled “6. See what a step gets”$ 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.
Which value wins?
Section titled “Which value wins?”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.