Jobs, Steps, and Actions
Jobs run on a runner; each job has steps that run commands or reusable actions.
Syntax
jobs:
<id>:
runs-on: ubuntu-latest
steps:
- uses: ...
- run: ...A job runs on a fresh runner (a virtual machine chosen with runs-on). By default jobs run in parallel; use needs to make one wait for another.
Steps
A job's steps run in order. A step is either:
run:— a shell command.uses:— a reusable action from the Marketplace, likeactions/checkout@v4.
Pass inputs to an action with a with: block.
Example
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test
deploy:
needs: test # wait for test to pass first
runs-on: ubuntu-latest
steps:
- run: echo "Deploying..."When to use it
- A CI pipeline defines separate lint, test, and build jobs that run in parallel, cutting total run time in half.
- A deploy job uses needs: [test] to ensure it only runs after the test job passes, preventing broken code from reaching production.
- A developer uses a community action (actions/setup-python) as a step to install a specific Python version without writing installer scripts.
More examples
Two parallel jobs in one workflow
Two jobs with no dependency on each other run concurrently on separate runners, reducing total pipeline duration.
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm run lint
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm testSequential jobs using needs
The deploy job waits for the test job to succeed before starting, creating a safe linear pipeline.
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: npm test
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- run: ./scripts/deploy.shUse a marketplace action as a step
The setup-python action installs the requested Python version on the runner so the pytest step finds the correct interpreter.
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: python -m pytest tests/
Discussion