Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 44 ยท CI/CD Fundamentals

Anatomy of a Pipeline

Meet the parts every CI/CD pipeline shares: triggers, jobs, stages, steps, runners, artifacts, environments and the exit codes that decide pass or fail.

GitHub Actions, Jenkins and GitLab use different words and different file formats, but underneath they are built from the same handful of parts. If you learn those parts once, every tool becomes easier, because you only have to learn its spelling for each idea. This lesson names the parts, shows how they fit together, and explains the one rule that decides whether a step passed: its exit code.

Nothing in this lesson needs an account. The read-only blocks show what real configuration looks like, and the runnable examples are stand-ins that behave like a tiny pipeline engine, so you can watch the same rules at work.

The parts of a pipeline

Here is the vocabulary, from the outside in.

Part What it is Typical example
Trigger The event that starts a run A push, a pull request, a schedule, a button click
Pipeline / workflow The whole automated process for one trigger "CI"
Stage A named phase that groups jobs (not every tool has this) build, test, deploy
Job A unit of work that runs on one machine, with its own clean workspace "unit tests"
Step One command or action inside a job, run in order npm test
Runner / agent / executor The machine (or container) that runs a job A hosted Linux VM
Artifact A file produced by a job and kept or passed on A compiled binary, a test report
Environment A named deployment target with its own settings and rules staging, production

Two relationships matter most. Steps inside a job run one after another on the same machine and share its files. Jobs are independent: each starts on a fresh machine, so by default one job cannot see another job's files. Anything that has to travel between jobs must be passed explicitly, as an artifact or an output.

flowchart TD
    T["Trigger: push to main"] --> P["Pipeline"]
    P --> J1["Job: build<br/>(runner A)"]
    P --> J2["Job: lint<br/>(runner B)"]
    J1 -->|"artifact: dist/"| J3["Job: test<br/>(runner C)"]
    J2 --> J4["Job: deploy"]
    J3 --> J4
    J4 --> E["Environment: staging"]

Jobs without a dependency (build and lint) can run in parallel on separate runners. The test job needs the build's artifact, and deploy waits for both.

How the three tools spell it

The same idea has different names in each tool:

Idea GitHub Actions Jenkins GitLab CI/CD
Whole definition Workflow Pipeline (a Jenkinsfile) Pipeline (.gitlab-ci.yml)
Phase (none; use needs) stage stage
Unit of work job stage containing steps job
One command step (run or uses) step a line in script
Machine Runner Agent Runner (with an executor)
Files kept Artifacts archiveArtifacts artifacts

GitHub Actions, Jenkins and GitLab Compared goes deeper. For now, just notice that the concepts map one to one.

A small real example

This is a complete GitHub Actions workflow. You do not need to understand every line yet; look for the parts from the table.

YAML
name: CI

on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: npm ci
      - name: Run tests
        run: npm test
      - uses: actions/upload-artifact@v4
        with:
          name: test-report
          path: reports/

The on: block holds the triggers. jobs: holds one job, test, and runs-on chooses its runner. The steps run in order: the first fetches the code, the next two run shell commands, and the last uploads a folder as an artifact. A Jenkinsfile or .gitlab-ci.yml would contain the same five ideas in a different syntax.

Exit codes decide pass or fail

How does a pipeline know that npm test failed? It does not read the output and guess. Every program that ends returns a small number called its exit code, and the convention is nearly universal:

  • 0 means success.
  • Any other number means failure. The specific value usually hints at the kind of failure, but the runner only cares whether it is zero.

A step passes when its command exits with 0. When a step fails, the job stops at that step by default and the remaining steps are skipped (a few special kinds of steps can still be told to run; later lessons cover that). A job fails if any step failed, and a pipeline fails if a required job failed. The shell chapter explains how exit codes work in scripts: see Exit Codes and Error Handling.

This has a practical consequence for you as a pipeline author: your scripts must exit non-zero when something is wrong. A script that prints "ERROR" but ends normally will make the pipeline green. The mistake is very common.

The stand-in below runs real child processes (small Node programs) and reports them the way a CI runner does: by exit code. It also shows continue-on-error-style behaviour, where a failing step is recorded but does not stop the job.

Node.js Steps pass or fail by exit code

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

In the first run the tests step exits with 1, so package is skipped and the job fails. In the second run the failure is recorded but the job carries on. In real tools the output of a failing step is still shown in the log; the exit code is what flips the status.

When you write your own script steps, start them with set -e (stop at the first failing command) and, in Bash, consider set -o pipefail so that a failure in the middle of a pipe is not hidden.

Artifacts and the clean-machine rule

Because every job starts on a fresh runner, files do not carry over. Suppose a build job compiles the code and a test job wants to run the compiled output. The build job must upload it as an artifact, and the test job must download it. Artifacts are also how you keep results after the machine is gone: test reports, coverage, installers.

The stand-in below models this rule. Each job gets its own empty "workspace" object. Run it and watch the second job fail until we pass the artifact through the shared store.

Node.js Jobs start clean: artifacts carry files between them

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

This is the stand-in for the real thing: in GitHub Actions the upload and download steps are actions/upload-artifact and actions/download-artifact, and in GitLab you list paths under artifacts:. Jenkins uses archiveArtifacts and stash/unstash. Caching and Artifacts covers them in detail.

Triggers, runners and environments

A trigger is any event your tool can observe: code pushed, a pull request opened, a tag created, a timer (cron), another pipeline finishing, or a person pressing a button. Good pipelines react only to the events they need. Running everything on every event wastes minutes and money.

A runner (GitHub and GitLab) or agent (Jenkins) is the machine that does the work. It can be hosted by the vendor, which is simple and clean, or self-hosted, which gives you control over hardware, network access and cost. You usually choose one by a label such as ubuntu-latest or linux.

An environment is a named place where software runs, such as staging or production. Tools attach rules and settings to environments: which secrets are available, who must approve a deployment, which branches may deploy. Keeping environments separate from jobs means the same build job can feed any of them. See Environments, Approvals and Deployments later in the track.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which part of a pipeline describes the machine that executes a job?

    The runner (called an agent in Jenkins) is the machine or container that runs the job. Triggers start the run, artifacts are files, and environments are deployment targets.
  2. 2. A step prints the word ERROR but its command exits with code 0. What does the pipeline report?

    Runners decide by exit code. Zero means success. Scripts must exit non-zero to signal failure, whatever they print.
  3. 3. Job B needs a file created in job A. What must you do?

    Each job starts on a clean machine. Files that must travel between jobs have to be uploaded as artifacts (or passed as outputs when they are small values).
  4. 4. How do steps inside one job relate to each other?

    Steps are sequential and share the job's workspace. It is jobs that are isolated from one another.

Summary

  • Every CI/CD tool is built from triggers, pipelines, stages, jobs, steps, runners/agents, artifacts and environments; only the spelling differs.
  • Steps run in order inside a job and share its workspace; jobs are isolated and start on a clean machine, so files and values must be passed on explicitly.
  • A step passes when its command exits with 0. Scripts must exit non-zero on failure, or the pipeline will be green when it should be red.
  • By default a failed step stops its job and skips the remaining steps; special settings can allow a failure to be recorded without stopping.
  • Artifacts keep results and move files between jobs; environments are named deployment targets with their own rules and secrets.

Next: GitHub Actions, Jenkins and GitLab Compared