Skip to content

Guides / Run jobs in order with requires and approvals

Run jobs in order with requires and approvals

By default every job in a workflow starts at once. This guide orders them: tests before build, build before deploy, and a person’s approval before production.

  • A config with test, build and deploy jobs, or your own.
  1. On the workflow entry, requires lists the entries that must finish first:

    .hatchrun/config.yml
    jobs:
    test:
    runs-on: ubuntu-latest
    steps:
    - run: make test
    build:
    runs-on: ubuntu-latest
    steps:
    - run: make build
    workflows:
    ci:
    on:
    push: {}
    jobs:
    - test
    - build:
    requires: [test]

    build starts after test succeeds. If test fails, build does not run.

  2. Entries with nothing to wait for run in parallel. An entry that requires several waits for all of them:

    .hatchrun/config.yml
    jobs:
    lint:
    runs-on: ubuntu-latest
    steps:
    - run: make lint
    unit:
    runs-on: ubuntu-latest
    steps:
    - run: make unit
    e2e:
    runs-on: ubuntu-26.04-4core
    steps:
    - run: make e2e
    build:
    runs-on: ubuntu-latest
    steps:
    - run: make build
    workflows:
    ci:
    on:
    push: {}
    jobs:
    - lint
    - unit
    - e2e
    - build:
    requires: [lint, unit, e2e]

    lint, unit and e2e run side by side. build waits for all three.

  3. An entry with type: approval runs nothing. It waits for a person, then the entries that require it start. Its key is its name and can be anything not used by another entry:

    .hatchrun/config.yml
    jobs:
    test:
    runs-on: ubuntu-latest
    steps:
    - run: make test
    deploy:
    runs-on: ubuntu-latest
    steps:
    - run: ./deploy.sh production
    workflows:
    release:
    on:
    push:
    branches: [main]
    jobs:
    - test
    - hold-production:
    type: approval
    requires: [test]
    - deploy:
    requires: [hold-production]

    The run shows hold-production as waiting once test passes. deploy starts after someone approves it.

  4. A job’s outputs are read by later jobs as ${{ needs.ID.outputs.NAME }}. Set the output from a step with an id:

    .hatchrun/config.yml
    jobs:
    version:
    runs-on: ubuntu-latest
    outputs:
    tag: ${{ steps.read.outputs.tag }}
    steps:
    - uses: actions/checkout@v5
    - id: read
    run: echo "tag=v$(cat VERSION)" >> "$GITHUB_OUTPUT"
    publish:
    runs-on: ubuntu-latest
    steps:
    - run: ./publish.sh "${{ needs.version.outputs.tag }}"
    workflows:
    release:
    on:
    push:
    branches: [main]
    jobs:
    - version
    - publish:
    requires: [version]
  5. Terminal window
    hatchrun validate
  • requires names entry ids: an entry’s name, or its key.
  • An entry that requires a matrix or parallel entry waits for every job planned from it.
  • If an entry is dropped by its branches or tags filter, every entry that requires it is dropped too.
  • A loop in requires is an error.

To hold one job for an organization admin, tied to a deploy target with its own branch rules and secrets, use an environment with approval instead.

An approval takes requires, branches and tags only. It cannot have a name, a matrix or parameter values.