> For AI agents: the complete documentation index is available at https://docs.hod.sh/llms.txt, the full documentation bundle is available at https://docs.hod.sh/llms-full.txt.

# Expressions and values

Expressions are [CEL](https://cel.dev). `if:` and `vars:` are expressions as written; every other string field takes a template, `${{ … }}`, whose value is put into the string. Expressions are type-checked when the pipeline compiles. There is no `${{ }}` in `run:`: values reach scripts only through `env:`.

## What an expression can read

| Name                                               | Where                                               |                                                                                              |
| -------------------------------------------------- | --------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| `event`                                            | everywhere but `runs-on`, which reads only `matrix` | The event that started the run ([below](#values-hod-gives-you))                              |
| `vars.<name>`                                      | everywhere but `runs-on` and earlier `vars`         | Named values ([Events and conditions](https://docs.hod.sh/pipelines/events.md#named-values)) |
| `matrix.<key>`                                     | in a matrix job                                     | The instance's values, as strings ([Matrix](https://docs.hod.sh/pipelines/matrix.md))        |
| `jobs.<name>.result`                               | a job's `if:`                                       | `"success"`, `"failure"`, `"cancelled"` or `"skipped"`, for the jobs in its `needs:`         |
| `jobs.<name>.outputs.<output>`                     | jobs that need it                                   | Typed outputs ([Files and outputs](https://docs.hod.sh/pipelines/files-and-outputs.md))      |
| `steps.<id>.outputs.<output>`, `steps.<id>.result` | later steps of the job                              |                                                                                              |

## Functions

- **`has(event.pull_request)`** tests whether a field is set. Reading a field that isn't set is an error when the expression runs.
- **`changed("src/**", "go.mod")`** is true when a changed file matches one of up to ten patterns (the rules of [`cache.inputs`](https://docs.hod.sh/pipelines/caching.md#the-step-cache)), and when Hod doesn't know what changed: tags, manual and scheduled runs, and `hod local run` without `--changed`. Its arguments must be string literals.
- **`event.semver`** is set for tags that are versions: an optional prefix ending in `/` or `@`, an optional `v`, then a semantic version.
- The CEL `strings` and `bindings` extensions are on: `s.startsWith("x")`, `s.split("/")`, `list.join(",")`, `cel.bind(…)`.
- An expression too costly to run (over 1,000,000 cost units, by its estimate) is rejected when the pipeline compiles, and evaluation is bounded at run time.

## Values Hod gives you

In expressions the event is `event`, and in every step's environment Hod sets the variables in the last column:

| Event field               | Example                                                                                                                             | Environment variable              |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
| `event.type`              | `"push"`, `"pull_request"`, `"tag"`, `"manual"`, `"schedule"`                                                                       | `HOD_EVENT`                       |
| `event.ref`               | `"refs/heads/main"`                                                                                                                 | `HOD_REF`                         |
| `event.sha`               | `"3f9c2a1…"`                                                                                                                        | `HOD_SHA`                         |
| `event.short_sha`         | `"3f9c2a1"`                                                                                                                         |                                   |
| `event.branch`            | `"main"` (pushes, scheduled runs, and manual runs on a branch)                                                                      | `HOD_BRANCH`                      |
| `event.is_default_branch` | `true` for a push to the default branch                                                                                             |                                   |
| `event.tag`               | `"v1.2.0"` (tags only)                                                                                                              | `HOD_TAG`                         |
| `event.name`              | `"nightly"`: the schedule's name (scheduled runs only)                                                                              | `HOD_SCHEDULE`                    |
| `event.semver`            | set for version tags: `prefix`, `major`, `minor`, `patch`, `prerelease`, `build`, `version` (`"1.2.0-rc.1"`, without `v` or prefix) |                                   |
| `event.before_sha`        | the commit before a push                                                                                                            |                                   |
| `event.changed_files`     | `["src/app.ts"]`                                                                                                                    |                                   |
| `event.commit_messages`   | the pushed commits' messages                                                                                                        |                                   |
| `event.repository`        | `full_name`, `default_branch`, `forge`                                                                                              |                                   |
| `event.actor`             | `login`                                                                                                                             |                                   |
| `event.pull_request`      | set for pull requests: `number`, `title`, `base_branch`, `head_branch`, `from_fork`, `draft`, `labels`                              | `HOD_BASE_BRANCH` (`base_branch`) |

Steps also get `CI=true`, `HOD=true`, `HOD_JOB`, `HOD_RUN_ID`, `HOD_RUN_ATTEMPT`, `HOD_WORKSPACE`, `HOD_OUTPUTS` (the directory a step writes its `outputs` to), `HOD_SECRETS` (the directory holding the step's granted secrets, one file each) and, for a step granted `identity`, `HOD_IDENTITY_TOKEN_FILE`. Hod's own variables (`HOD` and the `HOD_*` names in this section) can't be set in `env:`; other names, such as `HOD_SERVER` for a job that calls `hod`, can.
