GitHub Actions by Example: Job Ordering

As mentioned in Parallel Jobs, jobs are run in parallel by default. You can force job ordering by using the needs keyword.

name: parallel-jobs
on:
  push:
jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Doing work parallel with job2"
  job2:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Doing work parallel with job1"
  job3:
    runs-on: ubuntu-latest

job1 must complete successfully before starting job3

    needs: job1
    steps:
      - run: echo "job1 done, running job3"

job2 and job3 must complete successfully before starting job4

  job4:
    runs-on: ubuntu-latest
    needs: [job2, job3]
    steps:
      - run: echo "job2 & job3 done, running job4"
  job5:
    runs-on: ubuntu-latest

This job will run after job1, even if job1 fails (see Context Variables)

    if: ${{ always() }}
    needs: job1
    steps:
      - run: echo "job1 completed with status ${{ needs.job1.result }}, running job5"

Next example: Job Matrix