Skip to main content

Job

A CI/CD job is a discrete unit of work in a pipeline that runs a set of steps in isolation on a runner and ends in pass or fail, which decides whether dependent jobs run.

Understanding CI/CD Jobs

What Is a Job and How Is It Different From a Stage or Step

A pipeline is made of stages, a stage holds one or more jobs, and a job runs a sequence of steps (commands) on a single runner. Jobs in the same stage can run in parallel, while a failed job normally blocks later stages. In GitHub Actions the structure is flatter: there are jobs and steps, and ordering comes from the needs keyword.

Job Isolation

Each job starts with a fresh environment. Environment variables and files from one job do not appear in another unless you pass them as job outputs or artifacts. This isolation keeps pipelines reproducible and prevents jobs relying on each other's hidden side effects.

flowchart LR A[Job: build] -->|output: image tag| B[Job: test] A -->|artifact: build report| B B --> C[Job: deploy] classDef job fill:#326CE5,color:#FFFFFF classDef end1 fill:#10B981,color:#FFFFFF class A,B job class C end1

Passing Data Between Jobs

YAML
jobs:
build:
runs-on: ubuntu-latest
outputs:
image-tag: ${{ steps.tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
- id: tag
run: echo "tag=${{ github.sha }}" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
with:
name: build-report
path: build-report.json
test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: build-report
- run: echo "Testing ${{ needs.build.outputs.image-tag }}"

Practical Commands

Bash
gh run list --workflow=deploy.yaml
gh run view 1234567890 --json jobs
gh run view 1234567890 --job 98765 --log
gh run cancel 1234567890
glab ci cancel 1234567

Troubleshooting

Symptom Check What to Look For
Fails immediately First step output Missing tool or wrong runner
Times out Duration and timeout setting A hung process
Jobs not parallel needs chain Unintended dependencies
Artifact missing downstream Upload and download names Names do not match
Tip

Split independent work into separate jobs. Parallel jobs finish sooner, can be retried individually, and give shorter logs.

Remember

Variables set in one job are not visible in another. Use job outputs or artifacts to hand data over.

Security

Never run untrusted fork code in a job that has access to secrets. Misusing pull_request_target can let an attacker exfiltrate them.

Common Mistake

One giant job with thirty sequential steps. It cannot run in parallel, cannot be partially retried, and produces one hard-to-read log.

Frequently Asked Questions

How does a job differ from a stage and a step?

A stage is a phase such as build or test. A job is the unit of work inside it and runs on one runner. A step is a single command or action inside a job. Jobs in a stage can run in parallel.

Why is my job missing a file created by an earlier job?

Each job runs in a clean environment. Upload the file as an artifact in the first job and download it in the later one, or pass small values with job outputs.

How can I make jobs faster and less flaky?

Cache dependencies, split independent work into parallel jobs, and remove hidden dependencies between jobs so they pass regardless of execution order.

Found a mistake, an outdated step or a broken link?