How to Run a Job After Another Workflow Completes in GitHub Actions
Some jobs should only fire after a separate workflow finishes; workflow_run chains them without merging the files.
Use the workflow_run trigger naming the upstream workflow, then gate the job on github.event.workflow_run.conclusion.
Steps
- Add a
workflow_runtrigger referencing the upstream workflow by name. - Filter on the branches and event types you care about.
- Gate the job with
if: github.event.workflow_run.conclusion == 'success'. - Read upstream metadata from the
github.event.workflow_runcontext.
Workflow
.github/workflows/after-ci.yml
on:
workflow_run:
workflows: ['CI']
types: [completed]
jobs:
deploy:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- run: echo "CI ${{ github.event.workflow_run.head_sha }} passed; deploying"Gotchas
- The triggered workflow runs from the default branch, not the head branch of the upstream run.
- Without the conclusion gate, the job also runs after failed and cancelled upstream runs.
- Latchkey runs these chained workflows on cheaper runners and retries the follow-up on transient launch failures.
Related guides
How to Pass Artifacts to a Deploy Workflow in GitHub ActionsHand a build artifact from one GitHub Actions workflow to a separate deploy workflow by downloading it via th…
How to Gate Deploy on a Successful Staging Deploy in GitHub ActionsBlock a production deploy in GitHub Actions until staging deploys successfully, using job dependencies and a…