Steps and jobs
A flow has either steps (a list) or jobs (named groups of steps), never both.
Each step is one command for your system’s shell: sh -c on Linux and macOS, cmd /C on Windows.
Every step starts a new shell, so cd or export in one step does not carry over to the next.
steps: - id: build run: make build timeout: 10m - id: test needs: [build] run: make test retries: 2| Key | Required | Default | Meaning |
|---|---|---|---|
id |
yes | Unique name of the step in this list. | |
run |
yes | The command line, as you would type it. | |
needs |
no | none | Ids of steps that must succeed first. For top-level steps only. |
env |
no | none | Variables for this step. Variables. |
secrets |
no | none | Stored secrets for this step. Secrets. |
dir |
no | see below | The folder the command starts in. |
timeout |
no | none | Ends the step when it runs longer: 90s, 5m, 1h30m. |
kill_timeout |
no | 10s |
Time the step has to stop on its own once TRUSS stops it, before it is killed. |
retries |
no | 0 |
Extra tries after a failure, 0 to 100. |
retry_delay |
no | none | Wait before each retry, same format as timeout. Needs retries. |
continue-on-error |
no | false |
true lets the run go on when this step fails. |
if |
no | none | A condition; the step runs only when it holds. Conditions. |
Order. A step starts when every step it needs has succeeded and a slot is free
(flow.concurrency). Without needs and with the default concurrency, steps run top to bottom.
Working folder. A step starts in the first of: its own dir, its job’s dir, flow.workdir,
the project folder. They replace each other; they are not joined. A relative dir is relative to the
project folder (for a flow file outside a project: the file’s folder). On Windows a path with a drive letter must be absolute (C:\work, not C:work).
A job is a named list of steps for one purpose: build, test, deploy.
jobs: lint: steps: - { id: vet, run: go vet ./... } test: steps: - { id: unit, run: go test ./... } build: needs: [lint, test] steps: - { id: compile, run: go build ./... }| Key | Required | Meaning |
|---|---|---|
steps |
yes | The job’s steps. They run in the order written, one after another. |
needs |
no | Ids of jobs that must succeed first. |
env |
no | Variables for every step of the job. |
secrets |
no | Stored secrets for every step of the job. |
dir |
no | Working folder for the job’s steps. A step’s own dir replaces it. |
if |
no | A condition for the whole job, checked once when its first step is ready. |
- A job id uses letters, digits,
.,_and-. In logs and in TRUSS Desktop a step of a job is namedjob/step, for examplebuild/compile. - Steps of a job cannot use
needs: they already run in order. Order comes from the job’sneeds. - Jobs that do not need each other run side by side, up to
flow.concurrency.
When something fails
Section titled “When something fails”The first failed step fails the run. Running steps are stopped, and nothing new starts, except
steps that ask for it with if: always() or if: failure(). A step fails when its command exits
with a non-zero code, cannot start, is ended by a signal, or runs longer than its timeout.
truss run then exits with 1.
Retries
Section titled “Retries”- id: fetch run: curl -fsS https://example.com/data.json -o data.json retries: 2 # at most 3 attempts retry_delay: 10s # wait between attemptsA failed attempt is run again, and timeout applies to each attempt. The result of the step is its
last attempt. The log shows every attempt under its own heading, and a retry line between them:
step fetch finished duration 0.210s exit 22step fetch retry 2 of 3 in 10.000sA step is not retried when you interrupt the run, or when TRUSS stopped it because another step failed.
continue-on-error
Section titled “continue-on-error”- id: lint run: make lint continue-on-error: trueThe failure is logged and shown, but the run does not fail and other steps go on. A step that
needs the failed step is skipped, unless its if says otherwise (for example if: failure()).
Conditions
Section titled “Conditions”if takes an expression. A step without if runs when every step it needs succeeded.
| Part | Meaning |
|---|---|
success() |
Every step this step needs succeeded (always true without needs). |
failure() |
At least one step this step needs failed, was stopped or timed out. |
always() |
True. |
env.NAME |
The value of NAME as the step would see it, or empty when unset. |
'text' or "text" |
A literal, with no escapes. |
== != |
Compare two values. |
! && || ( ) |
Not, and, or, grouping. |
An expression without a status function means success() && (...). Quote the whole expression
when it starts with ! or contains : .
steps: - { id: build, run: make build } - { id: deploy, needs: [build], if: env.STAGE == 'prod', run: make deploy } - { id: notify, needs: [build, deploy], if: failure(), run: ./tell-the-team.sh } - { id: cleanup, needs: [build, deploy, notify], if: always(), run: make clean }- On a job,
ifis checked once, when its first step is ready. If false, every step of the job is skipped. - A skipped step is logged with the reason (
because its if condition is false, orbecause step build did not succeed) and shown as skipped in TRUSS Desktop. The log never prints the values an expression compared. - A step with
always()and noneedsstarts at once. Useneedsto run it last. - After a failure, only steps whose condition calls
always()orfailure()start.
How a step is stopped
Section titled “How a step is stopped”TRUSS stops a step when its timeout passes, when you cancel the run (truss cancel, Ctrl-C),
when another step fails and the run ends early, and when the daemon stops.
- Linux and macOS: every process the step started gets
SIGTERM, so a script can clean up (trap 'rm -f "$LOCK"' TERM). Whatever still runs afterkill_timeout(default10s, at most1m) getsSIGKILL. Duringtruss run, a second Ctrl-C kills at once. - Windows: the step and everything it started end at once.
kill_timeouthas no effect. - A stopped step counts as failed, even if it exits
0. Steps withif: failure()still run. - A process that leaves the step’s process group on purpose (
setsid, a daemonizing tool) is neither asked nor killed.