Skip to the content
Forge

Runs

Starting runs and following them, their logs, usage, artifacts, debug shells and cancelling.

Every path is under /api/v1; see the API for authenticating, errors and rate limits, and the schemas for the bodies.

The project's runs, newest first (run:read)

GET /api/v1/projects/{project}/runs

Parameter In Description
project path ID
state query RunState
limit query integer
cursor query string: next_cursor of the previous page

Answers:

  • 200: OK, object with the fields below
Field Type Description
next_cursor string
runs array of Run, required

Errors: 400, 403, 404 (how errors look).

Queue a run (run:create)

POST /api/v1/projects/{project}/runs

Parameter In Description
project path ID
Idempotency-Key header string: Makes retries safe: the same caller sending the same key again gets the run created the first time (200) instead of a new one; with a different body, 409 idempotency_key_reused.

Body (application/json): object.

Field Type Description
name string
spec RunSpec, required Everything needed to start a run. Omitted resources and timeouts get defaults; the stored spec has them filled in. Env values are stored and shown as they are: name secrets in secrets instead.

Answers:

  • 200: Created earlier with the same Idempotency-Key, Run
  • 201: Queued, Run

Errors: 400, 403, 404, 409, 422, 429 (how errors look).

Follow the project's runs live (run:read)

GET /api/v1/projects/{project}/runs/stream

Server-sent events. A run event, its data a Run, follows whenever a run is created, changes state or is asked to cancel; id is the change time in Unix microseconds. Reconnecting with Last-Event-ID (EventSource does this) goes on from there; without it the stream starts with the last few seconds. A run may come again unchanged: keep the latest by id. An error event means reading failed; reconnect. Streams close after 30 minutes and are authorized again on reconnect. Comments (: ping) keep idle streams open.

Parameter In Description
project path ID
Last-Event-ID header string

Answers:

  • 200: An event stream, string

Errors: 400, 404 (how errors look).

A run (run:read on its project)

GET /api/v1/runs/{run}

Parameter In Description
run path ID

Answers:

Errors: 404 (how errors look).

What the run's variables resolved to when it was created (run:read)

GET /api/v1/runs/{run}/variables

Parameter In Description
run path ID

Answers:

  • 200: OK, object with the fields below
Field Type Description
variables array of ResolvedVariable, required

Errors: 404 (how errors look).

The secrets and registries the run uses and the versions it pinned, never values (run:read)

GET /api/v1/runs/{run}/secrets

Parameter In Description
run path ID

Answers:

  • 200: OK, object with the fields below
Field Type Description
registries array of object, required The registries it pulls with or pushes to and the login versions it pinned.
secrets array of object, required

Errors: 404 (how errors look).

What happened to a run, oldest first (run:read)

GET /api/v1/runs/{run}/events

Parameter In Description
run path ID

Answers:

  • 200: OK, object with the fields below
Field Type Description
events array of RunEvent, required

Errors: 404 (how errors look).

Wait until a run has finished (run:read)

GET /api/v1/runs/{run}/wait

Answers once the run is in a final state (succeeded, failed, timed_out, cancelled, lost), or when the timeout passes, with the run either way. Call again while its state isn't final.

Parameter In Description
run path ID
timeout query string: A duration up to 2m, e.g. 30s; 0 answers at once.

Answers:

  • 200: The run, finished or not, Run

Errors: 400, 404 (how errors look).

A run's output (run:read)

GET /api/v1/runs/{run}/logs

Output lines as records, from offset (a byte offset into the log; 0 is the start) on, as far as the server has them. Read on from next_offset; once complete is true there is no more. An offset inside a record moves to the next one. A run keeps up to 64 MiB of output by default; a forge record says when the rest was dropped.

Parameter In Description
run path ID
offset query integer (int64)

Answers:

  • 200: OK, object with the fields below
Field Type Description
complete boolean, required
next_offset integer (int64), required
records array of LogRecord, required

Errors: 400, 404, 410 (how errors look).

A service's output (run:read)

GET /api/v1/runs/{run}/services/{service}/logs

Like a run's output (getRunLogs), for one of its services. Each service keeps up to as much output as the run.

Parameter In Description
run path ID
service path string
offset query integer (int64)

Answers:

  • 200: OK, object with the fields below
Field Type Description
complete boolean, required
next_offset integer (int64), required
records array of LogRecord, required

Errors: 400, 404, 410 (how errors look).

A run's CPU and memory over time (run:read)

GET /api/v1/runs/{run}/usage

What the run's process and each of its services used while the process ran, as its runner measured it every few seconds: so far while it runs, then final. Each point is the highest CPU (millicores) and memory (without reclaimable page cache) read in the interval ending at offset_ms after the process started; a long run's points cover longer intervals, at most 720 per container. Points at the same offset line up across containers. Empty for runs that didn't run, ran only a few seconds, or ran on an older runner. Kept and expired with the run's logs.

Parameter In Description
run path ID

Answers:

Errors: 400, 404, 410 (how errors look).

Follow a run's output live (run:read)

GET /api/v1/runs/{run}/logs/stream

Server-sent events. Each record of the log is one message event: data is a LogRecord, id the byte offset after it. Reconnecting with Last-Event-ID (EventSource does this) goes on from there; without it the stream starts at offset. Once the log is complete an end event follows and the stream closes, so clients should stop reconnecting then. An error event means reading failed; reconnect. Streams close after 30 minutes and are authorized again on reconnect. Comments (: ping) keep idle streams open.

Parameter In Description
run path ID
offset query integer (int64)
Last-Event-ID header string

Answers:

  • 200: An event stream, string

Errors: 400, 404, 410 (how errors look).

The Markdown the run wrote to $FORGE_SUMMARY (run:read)

GET /api/v1/runs/{run}/summary

Decision 189. Masked like the run's log, at most 1 MiB, uploaded by the runner once the run's process has exited. It is what the run wrote, so treat it as untrusted text: render it without raw HTML, as the run page does. 404 when the run has no summary (yet, or its data expired).

Parameter In Description
run path ID

Answers:

  • 200: OK, object with the fields below
Field Type Description
markdown string, required

Errors: 404, 410 (how errors look).

What the run's test reports said (run:read)

GET /api/v1/runs/{run}/tests

Decision 189. The JUnit, Cobertura and LCOV files the spec's reports globs matched, masked by the runner and read by the server once the run's process exited: totals, line coverage, notes on what couldn't be read, the failed cases (at most 200) and the 20 slowest. Messages are the run's own text. 404 when the run has no reports (yet).

Parameter In Description
run path ID

Answers:

Errors: 404, 410 (how errors look).

A run's artifacts, one per output path the runner reported (run:read)

GET /api/v1/runs/{run}/artifacts

Parameter In Description
run path ID

Answers:

  • 200: OK, object with the fields below
Field Type Description
artifacts array of Artifact, required

Errors: 404 (how errors look).

Download a stored artifact (run:read)

GET /api/v1/runs/{run}/artifacts/{artifact}/download

Parameter In Description
run path ID
artifact path ID

Answers:

  • 200: The file, or the directory as .tar.gz, as an attachment., string (binary), string (binary)

Errors: 404, 410 (how errors look).

Cancel a run (run:cancel)

POST /api/v1/runs/{run}/cancel

A queued run, or one awaiting approval, is cancelled right away. A run on a runner gets cancel_requested and its runner stops it.

Parameter In Description
run path ID

Answers:

  • 200: The run after the request, Run

Errors: 403, 404, 409 (how errors look).

Keep an ended run from retention (run:manage)

PUT /api/v1/runs/{run}/keep

Its logs, artifacts (their own expiry too) and record stay until it is unkept. What it holds then counts against the organization's kept_bytes quota: 409 quota_exceeded past it, 409 run_not_ended for a run that hasn't ended, 410 once its data expired. Keeping a kept run changes nothing.

Parameter In Description
run path ID

Answers:

  • 200: The run, kept, Run

Errors: 403, 404, 409, 410 (how errors look).

Unkeep a run (run:manage)

DELETE /api/v1/runs/{run}/keep

Retention then deletes what is past the organization's retention on its next pass.

Parameter In Description
run path ID

Answers:

  • 200: The run, no longer kept, Run

Errors: 403, 404 (how errors look).

Re-run an ended run with a debug shell (run:debug)

POST /api/v1/runs/{run}/debug

Starts the run's next attempt as its creator, with the same pinned spec, secrets and variables as a retry, and holds its container once its process exited so someone with run:debug can open a shell in it. Only on the project's or organization's own runners; a debug run isn't retried. 409 not_debuggable (the message says why) for a run that is still active, isn't a container run, is an approval step, a deploy, pushes images, runs a fork's pull request, or is a step of a flow run that is still running.

Parameter In Description
run path ID

Body (application/json): object.

Field Type Description
keep_minutes integer Up to the organization's debug_keep_seconds quota, in minutes (422 past it). Default 15, or the quota when it is less.
when one of on_failure, always Default on_failure.

Answers:

  • 201: The debug run, Run

Errors: 403, 404, 409, 422 (how errors look).

Open a debug shell in a held debug run, as a WebSocket (run:debug)

GET /api/v1/runs/{run}/shell

Upgrades to a WebSocket with a terminal in the run's container, while the run is debugging: its env, env secrets, working directory and user. Binary messages are the terminal's bytes both ways; text messages are JSON: {"resize": {"cols", "rows"}} from the client, {"end": {"exit_code"}} or {"end": {"message"}} from the server once the shell ended, before it closes the WebSocket. One shell per run at a time; it ends when it exits, after 10 minutes without input, or with the run. A browser's Origin must be this server. Opening and closing it are audited (run.shell_open, run.shell_close: size, duration, byte counts, exit code), never its contents. 409 not_debugging for a run that isn't held for debugging, shell_unavailable when its runner can't open one (one is open already, or it is no longer held).

Parameter In Description
run path ID
cols query integer
rows query integer

Errors: 101, 403, 404, 409, 422, 503 (how errors look).