# Refusals

> The refusals you are most likely to meet when a pipeline file is compiled, and what to do about each.
> **Available** in repositories branchd reads pipeline files for. It is switching repositories on one at a time: until yours is, it keeps running its `.forge-ci.yaml` or `.xeonr-ci.yaml`. See [What is available](https://docs.branchd.run/branchd/pipelines#what-is-available).

A refused file has no run. `branchd ci lint` and `branchd ci plan` print the
same refusal that the run would, as `invalid pipeline file: <file>:<line>: <message>`. Where the message is about a file a `uses:` read, it names that
file and line, then each `uses:` that led there:
`…; used by .branchd/pipelines/ci.yaml:6 (uses ./outer)`. Messages below
are shortened with `…`; the part you will see is enough to find them.

## Files and layout

| Message                                                                                     | What to do                                                                                                                          |
| ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `a pipeline file ends in .yaml, not .yml`                                                   | Rename the file.                                                                                                                    |
| `on: is required: it says when the pipeline runs …`                                         | Add `on:`.                                                                                                                          |
| `jobs: is required, and holds at least one job`                                             | Add a job.                                                                                                                          |
| `… and .branchd/pipelines/ are both here: a repository uses one layout …`                   | Remove the older CI file once its jobs are in pipeline files.                                                                       |
| `… are both named "A"; checks are named <pipeline> / <job>, so a pipeline's name is unique` | Give one file another `name:`.                                                                                                      |
| `line 2: did not find expected ',' or ']'`, and other YAML errors                           | The file is not valid YAML at that line. A flow map or list (`{…}`, `[…]`) with a comma or colon in a value needs the value quoted. |

## Keys

| Message                                                                                                     | What to do                                                                                                                                                                                                                                                                                                                                   |
| ----------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `job "j": unknown key "imag" (steps, uses, with, …)`                                                        | A misspelt key; the list is every key allowed there. The same form appears for every map: `checkout: unknown key …`, `cache: unknown key …`.                                                                                                                                                                                                 |
| `stages: do not exist in a pipeline file; order jobs with needs:`                                           | Delete `stages:`; add `needs:` to each job.                                                                                                                                                                                                                                                                                                  |
| `variables: is env: in a pipeline file`                                                                     | Rename it. Each GitLab CI key is refused with its replacement in the message: `script:`, `rules:`, `tags:`, `extends:`, `when:`, `allow_failure:`, `resource_group:`, `parallel:`, `interruptible:`, `before_script:`, `after_script:`, `default:`, `workflow:`, `include:`. See [Coming from GitLab CI](https://docs.branchd.run/branchd/pipelines/from-gitlab-ci). |
| `max-parallel: is not available yet: pipelines cannot limit how many jobs of a run run at once; remove it`  | Remove it: branchd cannot yet limit how many jobs of a run run at once.                                                                                                                                                                                                                                                                      |
| `permissions: unknown permission "issues" (contents, pull-requests, checks, releases, packages, pipelines)` | Use a name from the list, each `read` or `write`. See [The job token](https://docs.branchd.run/branchd/pipelines/job-token).                                                                                                                                                                                                                                         |
| `a preset of this repository (./presets/x) cannot run on the forge yet: …`                                  | Publish the preset in another repository and use `<group>/<repo>/<path>@v1`.                                                                                                                                                                                                                                                                 |
| `preset branchd/presets/service@v1: …`                                                                      | The preset refused its `with:`; the message names the key. A preset you may not read is refused as one that does not exist.                                                                                                                                                                                                                  |
| `job "a": step 2 (…/lantern-apply) must be marked isolated: true: this job has other steps, …`              | Add `isolated: true` and a `workspace:` listing what it needs; the message prints the step as it should be. See [Isolate a step](https://docs.branchd.run/branchd/pipelines/isolated-steps).                                                                                                                                                                         |
| `concurrency.group is a name of 1 to 200 characters`                                                        | Give the group a name, such as `deploy-${{ branch }}`.                                                                                                                                                                                                                                                                                       |

## Jobs and needs

| Message                                                                                                        | What to do                                                                                                                            |
| -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `job "j": image is required (set it on the job or under defaults:)`                                            | Add `image:`, or `defaults: {image: …}` for every job.                                                                                |
| `job "j": steps: is required, a list of {run: …}`                                                              | Add `steps:`, or `uses:` to call a pipeline.                                                                                          |
| `job "build:api": a job id is letters, digits, _ and -, starting with a letter or _`                           | Rename the job: `build-api`.                                                                                                          |
| `job "j" needs "nope", which is not a job of this file (needs across pipelines do not exist)`                  | Fix the id. A job cannot need a job of another file.                                                                                  |
| `job "j" needs "a", which does not run here (if … is false); mark the need optional: true if that is expected` | Give `j` the same `if:` as `a`, or write `needs: [{job: a, optional: true}]`. Check with `branchd ci plan` for the event in question. |
| `job "j": if: failure() in a job's if: is not available …`                                                     | Use `if: always()` on the job, and check the outcome in a step.                                                                       |
| `job "j": matrix.fail-fast must be true or false`                                                              | Write `true` (the default) or `false`.                                                                                                |
| `job "j": a matrix job has no outputs: which cell's would they be?`                                            | Move the output to a job without a matrix.                                                                                            |
| `job "j": artifacts: "." is or holds .branchd/run/ …`                                                          | Name the directories to keep (`dist`), not the whole workspace.                                                                       |
| `job "t": a trigger: job runs nothing in this repository, so it takes no image (…)`                            | Remove the key; a trigger job takes only the keys listed.                                                                             |
| `job "j": tag "deploy" is … deploy runner, which runs only the steps …`                                        | Remove `deploy` from `runs-on`.                                                                                                       |

## Expressions and outputs

| Message                                                                                                            | What to do                                                                                                                                                         |
| ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `github is not a context (branch, tag, event, …)`                                                                  | Use one of the listed contexts: `${{ sha }}`, not `${{ github.sha }}`. See [Expressions](https://docs.branchd.run/branchd/pipelines/expressions).                                          |
| `hashFiles() is not a function (changed, exists, contains, …)`                                                     | Use a listed function; for a cache keyed on files, use `cache.files`.                                                                                              |
| `inputs.x: this pipeline declares no inputs …`, `inputs.x is not declared (inputs: …)`                             | Declare the input under `on: manual`, `on: trigger` or `on: call`.                                                                                                 |
| `job "j": if: > with an output is not available: an output is a string, compared with == or !=`                    | Compare the output with a string (`== 'true'`), or use `contains`, `startsWith` or `endsWith`. See [if: on outputs](https://docs.branchd.run/branchd/pipelines/expressions#if-on-outputs). |
| `step 2: if: > with an output is not available: an output is a string, compared with == or !=`                     | As for a job's `if:`: compare with a string, or test the output inside the step's `run:`.                                                                          |
| `run: needs.a.outputs.o: job "a" is not among this job's needs`                                                    | Add `a` to `needs`.                                                                                                                                                |
| `job "j": outputs.o is "a\nb", which has a line break; an output is one line`                                      | Keep each output to one line.                                                                                                                                      |
| `jobs.j.env: "a-b" is not a variable name`                                                                         | Use letters, digits and `_`.                                                                                                                                       |
| `job "j": step 1 sets an EXIT trap, which would replace the one that runs step 2 (if: always()) after a failure …` | Set the trap in a subshell, `( trap … EXIT; … )`, or add `shell: bash` to the step.                                                                                |

## Steps

| Message                                                                                                                                        | What to do                                                                   |
| ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| `job "j": a typed step runs in its own image, so the job takes no image`                                                                       | Remove `image:` from that job.                                               |
| `job "j": step 1: uses: ci/nope@1: a typed step is used by its repository's path, <group>/<repo>/<path>@<version>, or by a name branchd knows` | Check the step's name, and use it by its address: `branchd/steps/<step>@v1`. |

## Composite steps and reusable pipelines

| Message                                                                                                | What to do                                                                                            |
| ------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
| `uses ./s: .branchd/steps/s/step.yaml does not exist`                                                  | Create the file, or fix the name. `./s` is `.branchd/steps/s/step.yaml`.                              |
| `uses ./s: with.nope is not an input (…)`                                                              | Declare the input in `step.yaml`, or fix its name.                                                    |
| `uses ./s needs the secret T: grant it to the job (secrets: [T])`                                      | Add the secret to the job's `secrets:`.                                                               |
| `matrix.a: a composite step reads its inputs, not the calling job's matrix; pass the value in with: …` | Declare an input and pass `${{ matrix.a }}` in `with:`. The same holds for `needs`, `env` and `vars`. |
| `uses: goes round in a cycle: …`                                                                       | A step uses itself, directly or through others.                                                       |
| `… it has no on: call, so a job cannot use it …`                                                       | Add `on: call` to the called file.                                                                    |
| `… requires input v, and job "c" gives none`                                                           | Add it under the calling job's `with:`.                                                               |
| `vars.X: a called pipeline reads its inputs, not the calling repository's settings variables …`        | Declare an input and pass `${{ vars.X }}` in the caller's `with:`.                                    |

## Other repositories

| Message                                                                                                                                                              | What to do                                                                                        |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| `@main is neither a version (@v1, @v1.4, @v1.4.2) nor a 40-character commit; branches are not accepted …`                                                            | Use a version tag.                                                                                |
| `xeonr/forge/steps has no tag that @v2 names (a tag v2.<minor>.<patch>)`                                                                                             | The publisher has no such version yet.                                                            |
| `xeonr/forge/steps does not list t in .branchd/packages.yaml, so other repositories may not use it (it lists …)`                                                     | Ask the publisher to list it, or fix the path.                                                    |
| `no repository in that path exists that this repository may read`                                                                                                    | The repository does not exist, or its visibility does not reach yours.                            |
| `job "c / j" sets environment: prod, and a pipeline of another repository may choose the environment only when the calling job "c" allows it (allow: [environment])` | Add `allow: [environment]` to the calling job, or set `environment:` on the calling job yourself. |

## Events and inputs

| Message                                                                       | What to do            |
| ----------------------------------------------------------------------------- | --------------------- |
| `on.schedule.cron: "0 3 * *" is not a five-field cron expression`             | Write five fields.    |
| `on.manual.inputs.c: a choice needs options`                                  | Add `options:`.       |
| `on.trigger needs from: (organisation, company, or a list of repositories) …` | Say who may start it. |

Source: https://docs.branchd.run/branchd/pipelines/errors
