Sub topic 15
Common pitfalls and anti-patterns
This chapter assumes you know what a pipeline is, how stages and jobs fit together, and how the delivery metrics from the previous chapter are calculated. It also assumes you can read a basic GitHub Actions YAML file. The chapter covers the mistakes that make a pipeline slow, untrusted, or risky, and how to spot and fix each one.
Why pipelines go wrong
Most pipeline failures come from weak habits around the pipeline, not from the tool itself. A pipeline is only useful if people trust it and act on its results. When developers stop believing a red build means something, the pipeline stops protecting you, even if it still runs.
Flaky tests that teach people to ignore failures
A flaky test passes and fails on the same code. Causes include timing assumptions, shared state between tests, and calls to real external services.
The damage is behavioral. After a few false alarms, developers re-run the build until it goes green. A real failure then looks like another flake.
Fixes:
- Track which tests fail intermittently, and fix or delete them quickly.
- Isolate tests from each other and from the network.
- Quarantine a flaky test in a separate non-blocking job while it is repaired, with an owner and a deadline.
A broken build that stays broken
If main is red for hours, nobody can tell whether their own change is safe. Treat a broken main as the team's top priority: revert the offending commit first, then investigate.
Rebuilding for each environment
Building separately for staging and production means production runs code that was never tested. Build once, store the artifact, and promote that same artifact. Environment differences belong in configuration, not in a rebuild.
Slow pipelines
A pipeline that takes 40 minutes encourages large, infrequent merges, which is the problem CI exists to remove. Speed it up by caching dependencies, running independent jobs in parallel, and running fast checks first so cheap failures stop the run early.
The example below runs lint and unit tests in parallel, and only starts the slower integration tests if both pass.
name: ci-fast
on:
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run lint
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm test
integration:
needs: [lint, unit]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run test:integrationSecrets and security shortcuts
Common mistakes are hardcoding credentials in the repository, printing secrets in logs, and giving every job broad permissions. Use the platform's secret store, scope credentials to the environment that needs them, and grant each job the least access it requires.
Manual steps hidden inside the pipeline
If a release needs someone to SSH into a server, edit a file, or run a script by hand, the pipeline is not the real process. These steps are undocumented and cannot be repeated reliably. Move each one into the pipeline definition so it is versioned and reviewed.
Skipping the safety net
Teams sometimes automate deployment to production without adequate tests, monitoring, or a rollback path. Continuous deployment without these only makes bad releases arrive faster. Add checks and a tested way to undo a release before you remove human approval.
Summary of anti-patterns
| Anti-pattern | Symptom | Fix |
|---|---|---|
| Flaky tests | Developers re-run until green | Quarantine, then fix or delete |
| Long-lived red main | No one trusts the build | Revert first, investigate after |
| Rebuild per environment | Production differs from what was tested | Build once, promote the artifact |
| Slow pipeline | Large, infrequent merges | Cache, parallelize, fail fast |
| Hardcoded secrets | Credentials in history or logs | Secret store, least privilege |
| Manual hidden steps | Releases depend on one person | Script them in the pipeline |
| No safety net | Failed releases reach users | Tests, monitoring, rollback |
Exercise
A team builds the application separately in the staging job and again in the production job. Tests pass in staging, but production has a bug that never appeared there. Which anti-pattern is this, and what change fixes it?
Show answer
It is rebuilding for each environment. The production build is a different artifact from the one tested in staging, so it can differ in dependencies or build inputs. Build once in an earlier job, upload the artifact, and have both the staging and production deploy jobs download and deploy that same artifact. Keep environment differences in configuration.
Exercise
Your pipeline takes 35 minutes, and developers now batch many changes into each pull request. Name two changes that shorten it without removing tests.
Show answer
Cache dependencies so installs are not repeated, and run independent jobs such as lint and unit tests in parallel. Ordering fast checks first so cheap failures stop the run early also works.