Skip to content
BIASED

Continuous integration

CI as a practice of merging small changes into one green main branch: pipelines as graphs of jobs on runners, caches and artifacts, the test pyramid and flaky tests, merge queues, pipeline time arithmetic, and CI security.

A practice, not a server

Building and pushing an image by hand means sometimes. Continuous integration turns those steps into something that happens on every change, on clean machines, with a visible result everyone trusts.

CI as named by Fowler and Beck is a team practice with three parts: integrate into one main branch at least daily in small changes; verify every integration with an automated build and tests on a clean machine; fix a broken main before merging anything else. A CI server only automates the second part. Long-lived feature branches with green checks still leave the integration problem of the baseline — merge conflicts and semantic clashes deferred for weeks. Trunk-based development with short-lived branches (hours to a couple of days) is the practice that makes the server useful.

Signal quality matters. A suite that is red 30% of the time teaches the team to ignore red. Treat a broken main as a stop-the-line event: revert or fix within minutes, not "we'll get it after standup."

A pipeline is a graph of jobs

A pipeline is a DAG of jobs; a job is ordered steps on one runner. Hosted runners are fresh VMs (no leaked state between jobs); self-hosted runners are cheaper per minute and dangerous if they keep workspace state, Docker layer residue or credentials across untrusted jobs.

  • An artifact must exist for downstream jobs — test reports, packages, image digests. Missing artifact fails the dependent job.
  • A cache is best-effort — dependency downloads, BuildKit layers, Go module cache. Missing cache must only slow the job down, never change the result.

Example calc pipeline: lint, unit, build start together; integration needs the image from build; release needs all four and runs only on main. Fan-out early, fan-in at the gates that need confidence.

Name digests in logs. When release promotes sha256:abc…, every environment that later runs that digest can be traced back to the commit and the pipeline run that produced it — the same content-addressing habit as Git and container images.

The pipeline critical path

With job durations djd_j, earliest finish EF(j)=ES(j)+dj\mathrm{EF}(j) = \mathrm{ES}(j) + d_j where ES\mathrm{ES} is the max EF of dependencies (0 if none). Pipeline wall time T=max⁡jEF(j)T = \max_j \mathrm{EF}(j) — the critical path.

Toy times: lint 1, unit 4, build 6, integration 5, release 1 → T=6+5+1=12T = 6+5+1 = \mathbf{12} minutes (serial sum 17). Lint has 10 minutes of slack before it would delay release; speeding lint to zero does not help. Shorten jobs on the path (faster builds, smaller images, parallel test shards), add runners when queue delay dominates, shard tests — until another path becomes critical.

Feedback budget. If developers push every ~30 minutes, a 40-minute pipeline means they start the next task before seeing results and context-switch back under interruption. Targeting TT under ~10–15 minutes for the common PR path (with a longer nightly for heavy E2E) keeps the loop closed. Measure p50/p95 of queue wait separately from job runtime — buying 2× runners fixes queue; rewriting tests fixes runtime.

Tests and the merge queue

Keep a test pyramid: many fast unit tests, fewer integration tests against real dependencies, few end-to-end journeys. An inverted pyramid (everything E2E) makes TT hours and flakes chronic. Flaky tests on the critical path destroy trust — quarantine them to a non-gating job the day they flake twice, then fix or delete; never "retry until green" as policy.

Semantic conflicts appear when two green branches merge: each passed against yesterday's main, together they break. A merge queue (merge train) retests the exact batch that will land on main before updating the branch tip. At high commit rates the queue is mandatory; at low rates a required up-to-date branch plus retest-on-merge is often enough.

CI security

The pipeline's credentials are production credentials. Pin third-party actions to commit SHAs (tags move); least-privilege tokens scoped per job; prefer OIDC to cloud roles over long-lived access keys in secrets stores; never expose secrets to untrusted fork pull requests; isolate self-hosted runners by trust tier (internal main vs public forks). Log and alert on secret use. A compromised CI can push a backdoored digest to the same registry production pulls from — treat runner hardening like production hardening.

Remote build caches and dependency proxies cut critical-path minutes when many jobs share the same lockfile. Keep cache keys keyed by lockfile hash and toolchain version so a bump invalidates cleanly. Hermetic toolchains (containerised builders with pinned digests) make "clean machine" literal: the runner image is part of the reproducibility story, not an invisible host OS.

Branch protection rules are CI policy in Git form: required checks, no force-push to main, linear history or merge queue as chosen. Social rules ("ask before merging red") fail at 2 a.m.; encoded rules do not. When a check is permanently skipped with a comment, treat that as an incident-sized exception with an expiry — otherwise the exception becomes the pipeline.

Next: Continuous delivery and deployment — promoting one immutable digest safely to users.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Go deeper — optional

Code and labs do not count toward the main percentage or the certificate.

  • CI gates: what blocks mergeoptional

    Build a lint/unit/integration/security matrix; decide what is required on PR vs nightly.

    ~15 min · easier on a computer · The matching course topic has been read.

    Self-check in the notebook — not part of mastery or the certificate.

Full notes

Answers are saved on the server and tied to this browser until you sign in.