Anatomy of a pipeline: triggers, jobs, runners, steps and reuse
Take a pipeline apart: event triggers, jobs and their dependencies, runners, steps, passing artifacts and values between them, and reusable workflows.
Contentsand lesson path
On this page
- Why it matters
- Triggers: which events start a workflow
- Jobs, runners and steps
- Passing values and files along, and reusing workflows
- Check your understanding
- Apply it
- Review prompt
Lessons of Continuous Integration
- Integrating continuously: small batches and a green main Concept · 15 min
- Anatomy of a pipeline: triggers, jobs, runners, steps and reuse Concept · 20 min
- Lab: a pull-request pipeline with caching and a test matrix Lab · 30 min
- Merge gates and reading a failing run Worked example · 20 min
- Securing the pipeline itself: lessons from compromised actions Worked example · 20 min
- Check: fix and harden a broken workflow Knowledge check · 6 questions
What you will learn
- Write a CI workflow (GitHub Actions or GitLab CI) that runs on pull requests and on main, with dependent jobs, dependency caching and a test matrix.
Prerequisites: Git Workflow, Build & Test Pipeline
01. Why it matters
Many pipeline bugs come from a wrong picture of how the parts run: a file that one job wrote is missing in the next job, a variable exported in one step is empty in the next, or a workflow never starts because its trigger does not match the event. Once you know which events start a workflow, where each job runs and how values travel between steps and jobs, you can read an unfamiliar pipeline, predict what it will do and find out why a run did something you did not expect.
02. Triggers: which events start a workflow
A workflow does not run by itself. The platform starts it when an event happens in the repository, such as a push, a new pull request or a scheduled time, and the workflow's on: key lists the events it reacts to. These choices decide when your pipeline runs and how much runner time it uses:
-
Source Control Events (
pushvs.pull_request): Apushevent fires whenever commits are pushed to a remote branch or tag. Apull_requestevent triggers on activity affecting pull requests (opening, synchronizing with new commits, reopening). On GitHub Actions, a pull request run does not test the branch alone: it tests a temporary merge commit (refs/pull/123/merge), which shows whatmainwould look like if the pull request were merged right now. This can expose a semantic merge conflict before the real merge, as far as your tests reach. -
Scheduled Triggers (
schedule): Configured via standard POSIX cron syntax (e.g.cron: "0 2 * * *"for nightly builds). Use them for work that is too slow to run on every commit, such as long regression suites, dependency vulnerability scans and performance benchmarks. -
Manual and External Dispatches (
workflow_dispatch,repository_dispatch): Let a person start a workflow from the web UI, or another system start it through the API, and pass inputs such as the target environment, the log level or the version to deploy. -
Path and Branch Filtering: Restricting triggers using
pathsandbranches(e.g.paths: ["services/auth/**"]) keeps changes to frontend assets or Markdown documentation from starting backend build jobs, which saves runner time. A workflow skipped this way reports no checks, so do not filter a workflow whose checks are required (lesson 04). -
Concurrency Cancellation: When a developer pushes several commits to a pull request in quick succession, only the newest commit needs a result, so earlier runs for that pull request can be cancelled. A concurrency group keyed on the workflow and ref does this. Cancel superseded pull-request runs only, and never cancel a build of
mainonce it has started. A concurrency group still keeps at most one waiting run by default, so when several commits land onmainquickly, a newer push replaces an older run that has not started yet. (GitHub'squeue: maxoption lets up to 100 runs wait, but it cannot be combined withcancel-in-progress: true.) The example below setscancel-in-progress: ${{ github.event_name == 'pull_request' }}for that reason.
03. Jobs, runners and steps
A workflow is built from three nested parts. Steps run inside a job, and each job runs on a runner:
-
Steps: The smallest unit of execution. Steps run sequentially on the same runner and share its filesystem: the checked-out workspace and anything a step writes to disk are still there for the next step. Each
runstep is a new shell process, however, soexport VAR=...andcddo not carry over. To pass an environment variable to later steps, append it to the file named by$GITHUB_ENV(echo "VERSION=1.4.2" >> "$GITHUB_ENV"); later steps see it, the writing step does not. Every step starts in the workspace directory unless you setworking-directory:. Steps can execute inline shell commands (run: npm test) or run an action, a ready-made step that someone has published, often a third party (uses: actions/checkout@<commit-sha>). -
Jobs: A logical collection of steps that execute on a single dedicated runner instance. By default, independent jobs run in parallel, each on its own runner. Do not expect files to pass from one job to another: on GitHub-hosted runners every job starts on a fresh virtual machine. To make a job wait for other jobs, list them under
needs(needs: [lint, typecheck]). The jobs and theirneedslinks form a directed acyclic graph (DAG): every link points one way, and no chain of links loops back to where it started. -
Runners: The machines that execute the jobs. Hosted runners are virtual machines that the CI vendor starts for one job and then deletes (for example GitHub-hosted
ubuntu-latest), so each job starts from a clean operating system and you maintain nothing. Self-hosted runners are your own virtual machines, servers or Kubernetes pods. Teams use them to reach private networks, special hardware (GPUs, Apple Silicon) or warm local caches. A self-hosted runner that is reused between jobs keeps files from earlier jobs, and on a public repository a malicious pull request can run code on it and reach your network, so keep such runners away from untrusted code.
name: ci
on:
push:
branches: [main]
pull_request:
branches: [main]
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
lint-and-validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Run code formatting and syntax checks
run: make lint
unit-and-integration-test:
needs: lint-and-validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Run test suite and emit structured reports
run: make test
- name: Upload JUnit test results artifact
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: junit-reports
path: reports/*.xml04. Passing values and files along, and reusing workflows
Because each job runs on its own machine, nothing passes from one job to the next unless you send it on explicitly. These are the ways to do that, plus two related features:
-
Step and Job Outputs: Individual steps expose scalar values (strings, commit hashes, version numbers) by appending a
name=valueline to the file whose path is in$GITHUB_OUTPUT(echo "version=1.4.2" >> "$GITHUB_OUTPUT"). Later steps in the same job read the value assteps.<id>.outputs.version, where<id>is the writing step'sid:. Jobs can then map these step outputs to job-level outputs, which downstream dependent jobs read via context expressions (needs.build.outputs.version). -
Persistent Build Artifacts: For large binary files, compiled packages, and test report bundles, jobs upload files to central object storage using artifact upload actions (
actions/upload-artifact, pinned by SHA as in the workflow above). Downstream deployment jobs download the artifact withactions/download-artifactrather than recompiling source code. -
Dependency Caching: Unlike artifacts (which pass data between jobs in the same pipeline run), caches (
actions/cache) preserve dependency directories across distinct sequential runs, keyed against package manifest hashes. -
Matrix Builds: A matrix strategy runs one job definition once for every combination of the values you list, such as operating system, runtime version or database driver (
strategy: { matrix: { os: [ubuntu-latest, macos-latest], python: ["3.11", "3.12"] } }). Matrix jobs run in parallel when enough runners are free, so a few lines of YAML test every combination. -
Reusable Workflows (
workflow_call): An organisation can keep a standard workflow in one central repository. Application teams call it with oneuses:line, so the same security scans and deployment gates run in hundreds of services without copying YAML.
05. Check your understanding
06. Apply it
Use these principles when you write workflows:
- Configure Concurrency Controls: Cancel superseded pull-request runs when new commits arrive, but never cancel a started
mainbuild; remember that a group keeps only one waiting run, so a quick series of pushes tomainskips the middle ones. - Fail Fast with Targeted Fast Gates: Place linters and static analysis in front of slow integration test jobs so simple mistakes fail in the first minutes instead of after the slow jobs.
- Isolate State Across Jobs: Never assume local files survive past the current job; use artifacts or remote storage for cross-job deliverables. Within a job, pass variables through
$GITHUB_ENVor step outputs, notexport. - Pin Actions to Full Commit SHAs: reference third-party actions by full commit SHA rather than by a branch or tag that can be moved, which closes one supply-chain path (lesson 05 covers the limits).
- Standardize via Reusable Workflows: keep shared security and compliance steps in one called workflow instead of a copy in every repository.
07. Review prompt
Without looking back: follow one pull request through a workflow, from the event that starts it, through jobs that wait for each other with needs, to an uploaded artifact. Why can a job not read files that an earlier job wrote, and what do you use instead? When do you pass a step output, and when an artifact? What does a reusable workflow give a team that copies of the same YAML in every repository do not?
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.