The issue opens pre-filled with this page title and URL.
A CI/CD pipeline is an automatic chain that turns source code into deployable
software: on every change pushed to Git, it tests it, builds it and deploys it,
and keeps a trace of each step. CI/CD stands for continuous integration
(testing every change) and continuous delivery or continuous deployment
(preparing the result for production, or deploying it there automatically).
It is not a script run remotely: the pipeline splits the work into isolated
jobs, runs them on runners, passes the results from one job to the next
as artifacts and deploys to protected environments. This lesson sets out
this vocabulary for a reader who has never written a pipeline, whatever the
tool.
What you will learn
Explain what a pipeline brings beyond a script
Describe jobs, stages and the execution graph
Place the role of a runner and the choice between runner types
Tell a cache from an artifact
Name the three invariants that make a real pipeline
A pipeline is not a script
A developer pushes her code to Git. A few minutes later, she gets a
notification: the tests pass, the container image is built, the deployment to
staging (the acceptance environment, a copy of production) is done. She
launched nothing by hand: the pipeline orchestrated it all.
You may have a Bash script that compiles and deploys your application. It is
not a pipeline: the difference does not lie in what the code does, but in
how it runs and what you can observe of it. A script can become a step
of a pipeline, but it brings neither orchestration nor traceability. The table
compares the two on five points.
Script
Pipeline
Runs on your machine or a fixed server
Runs in a controlled, isolated environment
Reads local environment variables
Explicitly declares its needs (secrets, artifacts)
Returns "it works" or "it crashes"
Exposes each step, its status, its duration
Leaves no trace once finished
Keeps logs, artifacts and history
Started by hand or by cron
Triggered by Git events (push, pull request, tag)
Swipe to see more
The diagram stacks the two. At the top, the "Script alone" block holds a single
box, ./deploy.sh, marked "all or nothing": the script succeeds or fails as a
whole, and you cannot see which command caused the problem. At the bottom, the
"Pipeline" block splits the work into lint, test, build and deploy, from left to
right. Under each step sit its logs (logs), and under the build there is one
more item, an artifact, that is, a file the following steps can reuse. The
legend tells the steps apart from what is kept, a log or an artifact.
A pipeline is organised in three levels, from smallest to largest: the job,
the stage and the execution graph. You find them, under similar names, in
GitHub Actions, GitLab CI or Jenkins.
The job, an isolated unit of execution
A job is the smallest unit of execution. It starts in a clean environment
(on an ephemeral runner, described below, nothing remains from the previous
job), prepares its tools, fetches the code, runs its commands, publishes its
results, then disappears. Its result is binary: the job fails as soon as one
of its commands exits with a return code other than 0, and it succeeds if all
of them exit with 0.
Typical jobs are called lint (code style), unit-tests, build-image or
deploy-staging. Two jobs with no dependency can run in parallel: a
failing linter does not stop the tests from running. On the other hand, if the
tests fail, the image is not built: the build depends on the tests.
The stage, grouping by phase
A stage groups jobs that serve the same goal. Stages run in order, and as a
general rule the jobs of one stage run in parallel. A classic split chains
"Validate" (lint and tests), "Build" (building the artifact) then "Deploy"
(staging, then production). It lets you fail fast: if the lint fails, there
is no point in building.
The diagram shows one frame per stage, to be read from left to right. In
Validate, lint and tests start together. Build produces the artifact. Deploy
is an exception to the parallel rule: deploy-staging then deploy-prod run
one after the other, because production is deployed only once staging has
passed. When two jobs of the same stage have to follow each other, it is
because a dependency was declared between them, as in the graph that follows.
Three stages run in order: Validate runs lint and tests in parallel, Build builds the artifact alone, Deploy deploys to staging then production, sequentially.deploy-stagingdeploy-prod3. Deploy (sequential)buildartifact2. Buildlinttests1. Validate (parallel)jobartifact producedexecution order
A complex pipeline forms a directed acyclic graph (DAG): the arrows always
point the same way and never loop back. The dependencies declared between
jobs, and no longer just the order of the stages, set what waits for what.
Reading this graph lets you shorten the duration: two unrelated jobs can start
together, without waiting for a whole stage to finish.
The diagram reads from top to bottom. Once checkout is done, lint, test
and security start together; security has its own colour because it is a
security check, not a plain execution. build waits for all three: it starts
only when they have all succeeded. It then unlocks dev directly, and a first
"(approval)": a person must validate before staging starts, hence the dotted
green line. staging in turn unlocks a second approval, which comes before
prod. Production therefore starts only after staging and a human validation.
The protections of a production environment are detailed in the section on
environments.
Execution graph: checkout unlocks lint, test and security in parallel; all three feed build, which unlocks dev and an approval followed by staging; staging unlocks a second approval, followed by prod.checkoutlinttestsecuritybuilddevstagingprod(approval)(approval)ExecutionControlWaitingFlowValidation
A runner (GitHub Actions, GitLab CI) or an agent (Jenkins, Azure
DevOps) is the machine that runs your jobs. The platform assigns it a job, it
fetches the code and configuration, runs the commands, then sends back the
logs and the status. The type of runner you choose affects security,
performance and cost.
Type
Advantages
Drawbacks
Hosted by the platform
Ready to use, maintenance included
Limited resources, no internal network access
Self-hosted
Full control, access to internal resources
Maintenance and security are on you
Ephemeral
Isolation between jobs, nothing persists
Slower start
Swipe to see more
A job has access to everything the runner sees: its file system, its
environment variables, the injected secrets and the reachable network. When
several projects share a persistent runner, a malicious job can read another
project's data. As soon as the context is sensitive, you therefore prefer
ephemeral runners, destroyed after each job.
Cache or artifact: what is the difference?
The cache speeds things up, the artifact passes results on: both store
files, but their roles differ. The cache keeps files between runs to avoid
recomputing them, typically npm or Maven dependencies. A first npm ci
downloads all the dependencies; with a cache of npm's download directory
(~/.npm), the next runs find them without downloading them again.
The cache is optional: its key is computed from a digest, often that of the
lock file (package-lock.json), it can go stale, and the job must work without
it. An artifact, on the other hand, is the output of a job, passed to the
following jobs or downloaded by a person. Since jobs are isolated, the deploy
job only sees the binary produced by build if that file was declared as an
artifact.
In the diagram, follow the arrow that goes from ./dist/ to the deploy job.
The build job runs npm run build, which produces the ./dist/ folder,
declared as an artifact. The deploy job fetches it before deploying. Without
that declaration, deploy would have nothing to fetch.
The build job runs npm run build and declares ./dist/ as an artifact; the deploy job fetches that artifact, then deploys.npm run build./dist/(artifact)fetches the artifactdeploysJob: deployJob: buildjob commandartifact producedartifact production and transfernext step in the job
The table sums up what separates them. The last row gives the test to
remember: if the absence of the file only makes the job slower, it is a
cache; if it makes it fail, it is an artifact. The retention period of
artifacts is configurable, with default values that vary by platform.
Aspect
Cache
Artifact
Purpose
Speed up
Pass on
Mandatory
No
Yes, for the jobs that depend on it
Persistence
Between runs
Limited retention period
Example
~/.npm/
dist/, test-report.xml
If missing
Slower job
Failed job
Swipe to see more
Deployment environments
An environment represents a deployment target: dev, staging,
production. Platforms let you attach protection rules and their own secrets
to it. This split stops a staging deployment from touching production by
mistake.
In the diagram, the "Pipeline" block chains test, build and deploy, then three
arrows leave deploy, one per environment, each with its condition. dev is
deployed automatically. staging waits for an approval. prod waits for an
approval, a delay and a backup of the data (backup on the diagram) made before
the production release. The closer you get to production, the stricter the
conditions: the arrow labels show it.
The pipeline chains test, build and deploy; deploy feeds three environments: dev automatically, staging after approval, prod after approval, delay and a backup of the data.autoapprovalapproval,delay,backuptestbuilddeploydevstagingprodEnvironmentsPipelinestep or automatic environmentenvironment with a safeguardsequence or automatic deploymentdeployment with conditions
The delay leaves time to cancel a deployment started by mistake. Platforms
often add two protections the diagram does not show: allowed time windows, and
restriction to the main branch.
The backup covers the data, a database for example. It does not roll the
application back: to return to the previous version, you redeploy the previous
artifact.
Each environment holds its own credentials: a staging database separate from
production, test API keys, tokens with reduced rights. A compromised staging
secret then gives no access to production.
Logs and observability
A well-logged job lets you understand what happened without re-running the
pipeline. Its logs show the commands run, their full output, the time of each
step, the execution context minus secrets, and the versions of the tools and
images used. A failure thus becomes a diagnosis rather than a riddle.
Masking secrets is not enough
Platforms mask known secrets in the logs, but an indirect leak remains
possible. An echo prints the value, and a value passed as a command argument
can reappear in an error message or in the process list. The countermeasure:
never let the secret go through the command line. curl can read a header
from a file, with the -H @file syntax.
Terminal window
# ❌ The secret shows up in the log
echo"Token: $API_TOKEN"
# ❌ The secret goes as an argument: it may come back in an error or in ps
printf is a shell builtin: the value does not go through a visible process.
umask 077 restricts the file to the job's user. RUNNER_TEMP is the job's
temporary directory on GitHub Actions, emptied at the end of the run; other
platforms offer an equivalent.
The health metrics of a pipeline
A healthy pipeline exposes four metrics: its average duration, its success
rate over a period, its flaky tests (which fail at random) and the time
spent waiting for a free runner. Alerts on a duration overrun or a drop in
success rate flag a degradation before it blocks the team.
What are the three invariants of a pipeline?
A real pipeline holds three guarantees: reproducibility, traceability
and observability. If one is missing, you have a script running remotely,
not a pipeline. Each one answers a question the team will ask sooner or later
in production.
Reproducibility: same input, same output
The same commit must produce the same artifact, whatever the time or the
machine. A pipeline that gives different results on each run no longer
deserves trust: you can no longer rely on what it produces.
Four causes break reproducibility: unpinned dependencies (an npm install
without a lock file), tests that depend on the time of day, calls to external
APIs without mocking, and a non-deterministic cache. The countermeasures match
them: lock files (package-lock.json, go.sum), images pinned to a precise
version (tag and digest) rather than latest, tests isolated from time and
external services, and a cache key computed from the lock file, so that a stale
cache is never reused.
Traceability: from the artifact back to the commit
When a bug shows up in production, you must be able to say which commit
introduced it, which pipeline built the artifact, which tests ran and who
triggered the deployment. Three practices make this possible: tag each artifact
with the SHA of the commit (its identifier) that produced it, keep the link
between each deployment and its pipeline, and keep the full logs of every job.
Observability: knowing what is going on
A pipeline exposes its state continuously, not just "green" or "red". A
pipeline that slows down gradually ends up blocking the whole team: imagine
a test job going from 2 to 15 minutes without anyone seeing it. You notice too
late, when nobody wants to push code any more. The health metrics seen above
are there to detect it in time.
What the pipeline reveals about the team
A pipeline is never neutral: it translates decisions, sometimes unconscious
ones. It says which tests are really mandatory, since a test you can ignore is
not. It says who can deploy to production: everyone, if a merge to main
triggers an automatic deployment; a few roles, if an approval is required.
It also says how long the team accepts to wait for feedback: a 45-minute
pipeline tends to discourage small commits, a 5-minute pipeline encourages
iteration. Conway's law (a system reflects the organisation of those who
build it) applies: an organisation where development and operations are split
often produces a fragmented pipeline, with a manual deployment after the
build. The lesson
CI, Continuous Delivery, Continuous Deployment
details how far automation can go.
Key points
A pipeline is an automatic chain, reproducible, traceable and
observable; a script is only one possible step of it.
The job is the isolated unit, the stage groups by phase, the
dependency graph sets the actual order.
The runner sees everything entrusted to it: an ephemeral runner removes
persistence between jobs.
The cache speeds things up and stays optional; the artifact passes
results on and becomes mandatory for the jobs that depend on it.
A secret never goes through the command line: log masking does not
protect against indirect leaks.
The three invariants are reproducibility, traceability and observability.
Knowledge check
Check that the essentials of this lesson are in place. The questions only
cover what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
6 questions
6 min
70% to pass
How it works
The timer starts when you click Start
Multiple choice, true/false and short answer questions
You can move between questions
Detailed results are shown at the end
Starts the quiz and the timer
⏱️--:--
0 / 6
Review
(0/0)
--:--
0%
Result saved on this device. It will be sent to your account at the next sync. Sync now
0Correct
0To review
0:00Time
-Level
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.