# Jobs and their results

> For the complete documentation index, see [llms.txt](https://docs-stg.ringleader.dev/llms.txt).


> A job on a workstation, such as a CI build, can report when it ends and what it exited with.


A job on a workstation, such as a CI build, can report when it ends and what it exited
with. You can then wait for the result from anywhere. The job writes its exit status to a file, and
the workstation's `Finished` condition then reports the result.

## Job results

A job reports its result by writing its exit status, a number from 0 to 255, to
`~/.ringleader/job-exit` in the
[login user](https://docs-stg.ringleader.dev/workstations/packages-tools-settings/users-environment-system-settings/#login-user)'s
home. The in-VM agent reads the file and reports the number to Ringleader, which records it
in the workstation's `status.jobResult` and sets the `Finished` condition. Status 0 means the
job succeeded, and any other status means it failed.
[`Finished` reasons](https://docs-stg.ringleader.dev/reference/resources/workstation/#finished-reasons) lists the
reasons.

`Finished` is `True` for a failed job too, because it reports that the job is over. A failed
job says nothing about the workstation's health, so `Finished` counts toward neither
`Configured` nor `Available`. A workstation whose job has never reported a result has no
`Finished` condition.

## Job results across a stop or start

A result belongs to the boot that produced it. A stop or a start clears `status.jobResult`,
and `Finished` turns `False` with reason `NoJobResult`. When the workstation boots, the
in-VM agent deletes any `job-exit` file left from the previous boot. A job on the new boot
then reports its own result.

## Job results over a shell connection

When you run a job with `rl shell`, the command passes the job's exit code through, and only
that client sees it. A job that runs detached, so that it outlives the connection, can write
`job-exit` instead. Ringleader then keeps the result, and any client can read it later.
[Shell exit codes](https://docs-stg.ringleader.dev/reference/cli/commands/workstation-access/#shell-exit-codes) shows how to tell a failed job
from a failed connection with `rl shell`.

## Report a job's result

To report a job's result, have the job write its exit status to `~/.ringleader/job-exit`
after it runs:

```bash
mkdir -p "$HOME/.ringleader"
make test; echo $? > "$HOME/.ringleader/job-exit"
```

Run the job as the login user, so that `$HOME` is that user's home. A value outside 0 to 255
isn't reported.

## Wait for a job to finish

To wait until the job ends, whatever it exited with, wait for the `Finished` condition:

```bash
rl workstation wait my-box --for condition=Finished --timeout 1h -n local
```

Then read the exit status:

```bash
rl workstation get my-box -n local -o jsonpath='{.status.jobResult.code}'
```

`rl workstation describe` shows the `Finished` condition and its message too.

## Next steps

- [Pools and leases](https://docs-stg.ringleader.dev/workstations/lifecycle/pools-leases/) give each CI
  job a fresh workstation, and take it back when the job is done.
- [Starts, stops and restarts](https://docs-stg.ringleader.dev/workstations/lifecycle/starts-stops-restarts/) stops a workstation when its job is long over, and
  [Deletion and delete deadlines](https://docs-stg.ringleader.dev/workstations/lifecycle/deletion-deadlines/) deletes it.
- [`rl <kind> wait [name...]`](https://docs-stg.ringleader.dev/reference/cli/commands/resource-verbs/#rl-kind-wait-name) lists the
  `--for` forms and its exit codes.
- [Conditions and their reasons](https://docs-stg.ringleader.dev/reference/resources/workstation/#conditions-and-their-reasons)
  lists the conditions you can wait for.

