# Job time limits

How long a workflow job may run, as on GitHub, the defaults a repository or organization can set, and the guard that stops a job that has gone silent.

## The workflow keys, as on GitHub

A workflow file's own keys work as they do on GitHub, and they win over every setting on this
page:

| Key                                        | What it does                                                                           | Default |
| ------------------------------------------ | -------------------------------------------------------------------------------------- | ------- |
| `jobs.<job_id>.timeout-minutes`            | The longest the job may run, in minutes. An expression works (`${{ inputs.minutes }}`) | 360     |
| `jobs.<job_id>.steps[*].timeout-minutes`   | The longest one step may run, in minutes; an expression works                          | none    |
| `jobs.<job_id>.steps[*].continue-on-error` | A step that fails or times out does not fail the job; the next steps run               | `false` |

When a **step** runs past its `timeout-minutes`, the step fails. With `continue-on-error: true` on
that step the job goes on with the next step, as on GitHub.

When a **job** runs past its time limit, it is cancelled as GitHub cancels it:

- the running step is stopped; steps with `if: always()` (or `if: cancelled()`) still run, within
  5 minutes, so a cleanup step can release what the job holds;
- the job ends **Timed out**, and its error says "The job has exceeded the maximum execution time
  of 90 minutes (timeout-minutes).";
- a job that `needs` it sees `needs.<job_id>.result` as `cancelled`. A job-level
  `continue-on-error: true` does not turn a timed-out job into a pass.

## Defaults for a repository and the organization

When a job's workflow sets no `timeout-minutes`, its time limit is, in this order:

1. the repository's default job timeout, when set;
2. the organization's default, when set;
3. 360 minutes, as on GitHub.

Whatever it comes from, it is never above the **organization's maximum**: 6 hours on a trial
organization, 72 hours otherwise. A job that asks for more runs for the maximum, and the first
lines of its log say so. A repository or organization default above the maximum is refused with
400 `jobTimeoutMinutes … is above this organization's maximum job time limit of … minutes (…); ask support to raise it`.
To raise the maximum, ask support.

Each job's page shows its **Time limit** and where it came from (from the workflow, repository
default, organization default, default as on GitHub, or organization maximum), and
`ci.runs.get` returns `timeoutMinutes` and `timeoutSource` for every job.

## The no-progress guard

Besides GitHub's time limit, Deutsche Cloud stops a job that has printed nothing for **30 minutes**:
a step waiting for an input that never comes, or a download that hangs, would otherwise hold its
runner until the time limit. At half of the guard the job's log warns, and at the guard the job is
stopped the same way as on a timeout (cleanup steps still run) and ends **Timed out** with the
error "The job was stopped as stalled: it printed no output for 30 minutes. …".

Anything the runner reports counts as output: a log line, a block of the log, a step starting or
ending. A step that is silent on purpose (a long test without output) needs a larger guard, or
none: set it per repository or for the organization, in minutes, with `0` turning it off. The
repository's setting wins over the organization's.

`actions/cache` restores get `SEGMENT_DOWNLOAD_TIMEOUT_MINS=5` by default, so a hanging cache
download gives up after 5 minutes and the job goes on without the cache, instead of waiting for
the guard. A job that sets the variable itself keeps its own value.

## Prerequisites

- For a repository: `git:UpdateRepository` on the repository.
- For the organization: `ci:PutOrganizationSettings` to change the defaults,
  `ci:GetOrganizationSettings` to read them, both on all of CI (`rn:ews::<organization id>:ci:*`).

Replace repo-id with the repository's id.

## Set a repository's defaults

**Console**
1. In the repository, choose **Settings**. **General** opens.
2. Under **Actions**, enter **Default job timeout in minutes** and **No-progress guard in minutes** (`0` turns the guard off).
   Leave a field empty to inherit: its hint shows the value that applies then and where it comes
   from.
3. Choose **Save changes**.

**CLI**
```sh
dcloud git repositories update repo-id --ci-job-timeout-minutes 120 --ci-stall-minutes 60
```

**API**
```http
PATCH /git/api/repositories/repo-id
{ "ciJobTimeoutMinutes": 120, "ciStallMinutes": 60 }
```

`null` for either field inherits again.

**Terraform:** not available. The time limits are not attributes of the Terraform repository resource yet.

## Set the organization's defaults

**Console:** not available. The organization's defaults are set with the CLI or the API.
**CLI**
```sh
dcloud ci settings set --job-timeout-minutes 180 --stall-minutes 45
dcloud ci settings get
```

**API**
```http
PUT /ci/api/settings
{ "jobTimeoutMinutes": 180, "stallMinutes": 45 }
```

`null` sets a field back to the default (360 and 30). `GET /ci/api/settings` also returns
`effectiveMaxJobTimeoutMinutes`, the organization's maximum.

**Terraform:** not available. The organization's CI settings are not a Terraform resource yet.

## Result

Jobs that a runner takes from now on get the new limits; a job that is already running keeps the
limits it started with. The job's page shows its **Time limit**.

## Related

- [Run GitHub Actions workflows](run-github-actions-workflows.md)
- [Cancel or re-run a run](cancel-or-rerun-a-run.md)
- [Change repository settings](/docs/git/guide/change-repository-settings)
- `ci.settings.set` · `dcloud ci settings set` · `git.repositories.update`
