Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 2 of 6 · Concept · 20 min · revision 3

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

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 (push vs. pull_request): A push event fires whenever commits are pushed to a remote branch or tag. A pull_request event 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 what main would 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 paths and branches (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 main once it has started. A concurrency group still keeps at most one waiting run by default, so when several commits land on main quickly, a newer push replaces an older run that has not started yet. (GitHub's queue: max option lets up to 100 runs wait, but it cannot be combined with cancel-in-progress: true.) The example below sets cancel-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:

  1. 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 run step is a new shell process, however, so export VAR=... and cd do 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 set working-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>).

  2. 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 their needs links form a directed acyclic graph (DAG): every link points one way, and no chain of links loops back to where it started.

  3. 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.

YAML · .github/workflows/ci.yml: triggers, a job dependency and an artifact
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/*.xml

04. 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=value line 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 as steps.<id>.outputs.version, where <id> is the writing step's id:. 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 with actions/download-artifact rather 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 one uses: line, so the same security scans and deployment gates run in hundreds of services without copying YAML.

05. Check your understanding

Practice check · 3 questions

Job isolation, step outputs and reusable workflows

Three questions on how a GitHub Actions pipeline passes work and values along.

Q1. In an automated CI pipeline, Job A compiles a binary into directory `dist/bin`. Job B needs to execute this binary in a subsequent stage. Why will Job B fail if it attempts to execute `./dist/bin` directly without downloading an artifact?
Q2. A shell step with `id: ver` calculates a version string. How does it publish the value so that later steps in the same job can read it as `${{ steps.ver.outputs.version }}`?
Q3. What is the primary governance and security benefit of utilizing Reusable Workflows (`on: workflow_call`) across a corporate microservice fleet?
Practice only: not graded, not saved, not evidence.

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 main build; remember that a group keeps only one waiting run, so a quick series of pushes to main skips 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_ENV or step outputs, not export.
  • 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.

Sign in to mark reading complete

Prove this skill

6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check