Skip to content

DevOps Operations / Continuous integration · Step 3 of 7

Lesson: Jobs, Steps, and RunnersSwitch
← DevOps Operations

Delivery and containers

Jobs, Steps, and Runners

How a workflow is split into jobs and steps, and which machines run them.

A workflow has three layers you need to keep apart: jobs, steps and runners.

The pieces

  • A runner is the machine that does the work.
  • A job is a group of steps that runs on one runner.
  • A step is a single task: a shell command (run) or a reusable action (uses).
yaml
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - name: Check shell syntax
        run: bash -n build.sh
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - run: ./test.sh

Parallel by default

Jobs run in parallel unless you say otherwise. Steps inside a job run one after another. If a step fails, later steps are skipped by default and the job fails.

To make one job wait for another, use needs:

yaml
  test:
    needs: lint
    runs-on: ubuntu-latest

Now test starts only after lint succeeds. If lint fails, test is skipped by default.

What is shared

With GitHub-hosted runners, each job gets its own fresh runner, usually a new virtual machine. Steps in the same job share the file system, so a file created by one step is there for the next. A different job does not see it. That is why both jobs above check out the code. To pass files between jobs, upload and download artifacts.

Each run step starts a new shell. A cd or an export in one step does not carry into the next. To pass a variable on, write it to the file named by GITHUB_ENV:

yaml
      - run: echo "APP_ENV=test" >> "$GITHUB_ENV"
      - run: echo "$APP_ENV"
test

Choosing runners

runs-on picks the machine. Labels such as ubuntu-latest, windows-latest and macos-latest select GitHub-hosted runners. The -latest labels move to newer releases over time, so name a specific version when you need stability.

A self-hosted runner is a machine you manage yourself. It can reach private networks and keep tools installed, but you must patch and secure it. Files can remain between jobs, and running untrusted code from public repositories on it is dangerous.

Try it

Write two jobs. In the first, run echo hi > note.txt. In the second, add needs and run cat note.txt. It fails because the machines are different. Then move both commands into one job and watch it pass. See the official documentation for runner labels, and the shell navigation lab to practise how cd behaves.

Check your understanding

Jobs, Steps, and Runners

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.