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.
Prerequisites
Section titled “Prerequisites”- A config with
test,buildanddeployjobs, or your own.
-
Make a job wait for another
Section titled “Make a job wait for another”On the workflow entry,
requireslists the entries that must finish first:.hatchrun/config.yml jobs:test:runs-on: ubuntu-lateststeps:- run: make testbuild:runs-on: ubuntu-lateststeps:- run: make buildworkflows:ci:on:push: {}jobs:- test- build:requires: [test]buildstarts aftertestsucceeds. Iftestfails,builddoes not run. -
Fan out and back in
Section titled “Fan out and back in”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-lateststeps:- run: make lintunit:runs-on: ubuntu-lateststeps:- run: make unite2e:runs-on: ubuntu-26.04-4coresteps:- run: make e2ebuild:runs-on: ubuntu-lateststeps:- run: make buildworkflows:ci:on:push: {}jobs:- lint- unit- e2e- build:requires: [lint, unit, e2e]lint,unitande2erun side by side.buildwaits for all three. -
Add an approval before deploy
Section titled “Add an approval before deploy”An entry with
type: approvalruns 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-lateststeps:- run: make testdeploy:runs-on: ubuntu-lateststeps:- run: ./deploy.sh productionworkflows:release:on:push:branches: [main]jobs:- test- hold-production:type: approvalrequires: [test]- deploy:requires: [hold-production]The run shows
hold-productionas waiting oncetestpasses.deploystarts after someone approves it. -
Pass values from one job to the next
Section titled “Pass values from one job to the next”A job’s
outputsare read by later jobs as${{ needs.ID.outputs.NAME }}. Set the output from a step with anid:.hatchrun/config.yml jobs:version:runs-on: ubuntu-latestoutputs:tag: ${{ steps.read.outputs.tag }}steps:- uses: actions/checkout@v5- id: readrun: echo "tag=v$(cat VERSION)" >> "$GITHUB_OUTPUT"publish:runs-on: ubuntu-lateststeps:- run: ./publish.sh "${{ needs.version.outputs.tag }}"workflows:release:on:push:branches: [main]jobs:- version- publish:requires: [version] -
Validate
Section titled “Validate”Terminal window hatchrun validate
How requires works
Section titled “How requires works”requiresnames entry ids: an entry’sname, 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
branchesortagsfilter, every entry that requires it is dropped too. - A loop in
requiresis 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.