Pipeline Troubleshooting
Diagnose failing builds, flaky pipelines, and bad deployments systematically: classify failures, reproduce locally, use evidence and bisection, fix causes, and use AI as a hypothesis generator.
Introduction
A red pipeline is a stalled team. Every minute it is broken, people wait, merge on top of a broken main, or rerun until green and hope. The skill that separates calm teams from stressed ones is diagnosing failures methodically: knowing where to look, how to narrow the cause, and how to stop the same failure from returning.
This lesson gives a diagnostic method, a catalog of common failure classes, and ways to use AI as an assistant, with the caution that confident explanations are not evidence.
Learning Objectives
- Classify pipeline and deployment failures.
- Apply a systematic diagnosis method: observe, hypothesize, test, fix, prevent.
- Reproduce pipeline failures locally and isolate differences.
- Find regressions by bisection and by comparing good and bad runs.
- Recognize common failure patterns across build, test, infrastructure, deployment, and runtime.
- Handle flaky and infrastructure failures properly.
- Use AI to analyze logs and propose hypotheses, and verify them.
- Write blameless failure records and playbooks.
1. Classify the Failure First
The first question is “what kind of failure is this?” because each class has a different owner and a different fix.
| Class | Signs | Typical cause | Owner |
|---|---|---|---|
| Code failure | A test or check fails consistently, reproducibly | A real defect or outdated test | Author |
| Environment difference | Passes locally, fails in the pipeline (or reverse) | Tool versions, OS, missing variables, timezone, file paths | Author and platform |
| Dependency failure | Build breaks without a code change | An unpinned dependency, removed package, registry outage | Author and platform |
| Flaky test | Same commit sometimes passes, sometimes fails | Timing, shared state, order dependence | Test owner |
| Infrastructure failure | Runner out of disk, timeouts, network errors | Resource limits, outages, quotas | Platform |
| Configuration or secret failure | Authentication errors, missing variables, wrong target | Expired secret, mis-scoped permission, wrong environment | Platform and owner |
| Pipeline definition failure | Stage skipped, wrong order, syntax error | A change to the pipeline itself | Author of the change |
| Deployment failure | Rollout stalls, health checks fail, errors rise | Bad artifact, incompatible migration, configuration, capacity | Release owner |
If the failure is shared by many unrelated branches at once, suspect main, a dependency, or infrastructure. If it affects one branch, suspect the change.
2. A Systematic Method
- Stop and stabilize. If main is broken or production is degraded, restore service first (revert, roll back, turn off a flag), and investigate after. Do not debug in a live incident when a rollback is available.
- Observe. Read the actual error, the first failure and not the last (later failures are often consequences). Note the stage, step, exact message, time, commit, and runner.
- Compare. What differs between the last good run and the first bad run? Commits, dependencies, configuration, runner image, time, data.
- Hypothesize. Write two or three candidate causes, ranked by likelihood and by cost to test.
- Test one hypothesis at a time, by reproducing, adding diagnostics, or changing one variable. Changing several things at once teaches nothing.
- Fix the cause, not the symptom. A rerun, a longer timeout, or a skipped test is a symptom fix.
- Prevent recurrence. Add a test, a check, an alert, a pin, or documentation, so that the class of failure is caught earlier next time.
- Record. A short blameless note: symptom, cause, fix, prevention.
3. Reading Logs and Evidence
- Start at the first error. Scroll up from the final failure message to the first abnormal line.
- Distinguish noise from signal: warnings that appear in every run are noise; a new warning is a clue.
- Check timing: a step that suddenly takes much longer, or a timeout near a round number, points to resource or network problems.
- Check exit codes and what they mean, and whether a step swallowed an error.
- Look at the environment: tool versions, environment variables (names, never values), runner image, disk and memory.
- Make the pipeline diagnosable: print tool versions at the start, upload logs, reports, and screenshots as artifacts on failure, and use clear step names. A failure that cannot be understood without rerunning is a pipeline defect.
4. Reproduce Locally
Because the pipeline calls the same commands as developers (lesson 2), reproduction is usually one command:
1
make test-integration
If it passes locally but fails in the pipeline, the difference is the cause. Narrow it:
- Run inside the same container image as the pipeline.
- Compare tool and dependency versions (print them in both places).
- Compare environment variables and configuration (names and non-secret values).
- Compare resources and time: CPU, memory, parallelism, time zone, locale, clock.
- Compare data and state: clean checkout versus accumulated local files, cached dependencies.
- Check order and parallelism: run tests in the pipeline’s order, with the pipeline’s concurrency.
If it fails locally too, it is almost always a code, test, or dependency problem, and ordinary debugging applies.
5. Finding What Changed
Bisection. When a regression appeared between two known commits, bisect: test the middle commit, discard half, repeat. A tool does this automatically with a script that returns pass or fail.
1
2
3
4
git bisect start
git bisect bad HEAD
git bisect good v0.1.0
git bisect run make test-unit
Run comparison. Diff the logs, versions, and configuration of the last good and first bad run. Many failures are caused by something that changed outside the repository: a base image, a dependency, a runner, a certificate, an expired secret.
Dependency changes. If the build broke without a commit, suspect an unpinned dependency or tool. This is why lock files and pinned images matter.
6. Common Failure Patterns
Build and dependencies
- “Cannot find package”: an unpinned or removed dependency, or a registry outage. Check the lock file, and use a mirror or cache for resilience.
- Works on a developer machine but not in a clean build: an undeclared dependency or a file that exists only locally.
- Different results between builds: nondeterminism; unpinned tools.
Tests
- Intermittent failures: shared state, timing, order dependence, real clocks or networks (the quality course). Quarantine with a deadline and fix.
- Timeouts on slow runners: tests that depend on speed; make them deterministic or increase resources deliberately.
- Passes alone, fails in the suite: leaked state between tests.
Containers and registry
- Image fails to start: wrong entry command, missing environment variable, non-root user lacking permission to write.
- Image pull errors: authentication, wrong tag, or a deleted image under a retention rule.
- Container killed repeatedly: out-of-memory or a failing liveness check.
Infrastructure code
- Plan shows unexpected replacement: a changed immutable attribute or a renamed resource.
- State lock errors: a previous run was interrupted; release the lock carefully after confirming nobody is applying.
- Permission denied: a scope change or missing role for the pipeline identity.
- Drift: a manual change conflicts with the code.
Deployment
- Rollout stalls: readiness never passes (a dependency unreachable, a migration not applied, a configuration value wrong), or insufficient capacity.
- Errors after deployment but healthy checks: the health check does not reflect real behavior.
- Migration fails or locks: a long lock or an incompatible change; apply the rollback or forward-fix plan.
- Works in staging, fails in production: a difference in data volume, configuration, permissions, or network.
Secrets and permissions
- Authentication failures after a long period of working: expiry or rotation.
- Works for one environment only: secrets or roles missing in the other.
7. Flaky and Infrastructure Failures
Do not treat them as “just rerun.”
- Record every flake, automatically if possible (rerun-and-compare detection). A flaky test is a defect with an owner and a deadline.
- Separate infrastructure failures from code failures in reporting, so that the team can see the real failure rate and the platform team can see theirs.
- Add retries only for known-transient operations (a registry pull), with limits and logging. Blanket retries hide real defects.
- Track pipeline reliability (success rate for runs with no code problem) and treat a drop as an incident for the pipeline itself.
8. Production Deployment Failures
When a deployment goes wrong in production, order matters:
- Decide rollback or fix forward, using the criteria agreed in advance (lesson 6). If in doubt, roll back.
- Communicate: state the problem and the chosen action in the release channel.
- Preserve evidence (logs, metrics, the failing artifact) before it is overwritten.
- Restore service, then investigate calmly.
- Review blamelessly afterward, and fix the process, tests, and monitors that let it through (the operations course expands incident management).
9. Using AI for Troubleshooting
AI is a fast reader of long logs and a good generator of hypotheses. It is not an oracle.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Act as a senior DevOps engineer helping to diagnose a failure.
Inputs (secrets redacted):
- Failing log excerpt, starting at the first error: [paste]
- The last successful run's equivalent excerpt: [paste]
- The diff of commits, dependency lock, and configuration between
the two runs: [paste]
- Pipeline definition for the failing stage: [paste]
- Environment facts: runner image, tool versions: [paste]
Tasks:
1. Summarize what the logs say happened, quoting key lines.
2. Identify the first abnormal event, and separate it from
consequences.
3. List differences between the good and bad runs.
4. List three to five hypotheses, ranked, each with the evidence for
and against it, and the cheapest test to confirm or reject it.
5. State what additional information would most reduce uncertainty.
Do not state a root cause as fact. Mark hypotheses as hypotheses.
Rules for using the output:
- Test hypotheses; do not apply fixes you do not understand. A suggested command may delete data, disable a check, or change permissions.
- Beware of confident wrong explanations. Models often propose common causes that fit the message but not your situation. Look for evidence in your logs.
- Redact secrets, tokens, and internal hostnames from logs before pasting.
- Give the model the comparison, not only the failure. Good-versus-bad context produces far better hypotheses than a single failing log.
- Keep a human decision on rollbacks, permission changes, and anything touching production.
More uses: clustering a month of failures to find the top causes; drafting the blameless failure record from the timeline; generating a playbook entry from a resolved failure; and reviewing a pipeline definition for the weaknesses identified in this lesson.
10. Playbooks
Turn solved problems into short playbook entries that anyone on the team can use.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
### Integration stage fails with "connection refused" to the database
**Symptoms:** Stage `integration` fails in under 30 seconds; log shows
connection refused to `db:5432`.
**Common causes:**
1. The database service was not ready when tests started.
2. The service definition for the stage was removed or misnamed.
**Check:** Look for the database health check line before the first test.
Run `make test-integration` locally against the composition file.
**Fix:** Wait for readiness in the stage setup. Do not add sleeps.
**Prevent:** Pipeline lint rule: any stage using a database must declare
the service.
Link each entry from the developer guide’s troubleshooting page. Update entries whenever the guidance proves wrong.
11. Practical Exercise
For SignalDesk (or your project):
- Make the pipeline diagnosable: print tool versions, upload reports and logs as artifacts on failure, and name steps clearly.
- Inject five failures on a branch, one for each of: a code defect, an unpinned dependency change, a missing environment variable, a flaky test, and a failing migration. For each, apply the method in this lesson without looking at your own injection, using a teammate if possible.
- Practice the local reproduction technique by running the failing stage in the pipeline’s container image.
- Practice bisection with a seeded regression across at least twenty commits.
- Give the AI prompt a good run and a bad run, check each hypothesis with a test, and record where the model was wrong.
- Write the pipeline failure classification into your dashboard or report: code, flaky, infrastructure, configuration.
- Write a playbook entry for each failure you diagnosed, and link them from the developer guide.
- Write a blameless record for one practice failure.
Verification
You are ready to continue when:
- Any failure can be classified and traced from the log artifact without rerunning.
- You can reproduce a pipeline failure locally in the same container image.
- Bisection and run comparison locate a regression in minutes.
- Flaky and infrastructure failures are recorded separately from code failures.
- Every practice failure has a record with the cause, the fix, and a preventive change.
- Each AI-suggested hypothesis was tested before any fix was applied.
Key Takeaways
- Classify the failure first; stabilize before investigating.
- Observe the first error, compare good and bad, test one hypothesis at a time, and fix causes rather than symptoms.
- Make pipelines diagnosable and reproducible with the same commands and images.
- Never treat flakes and infrastructure faults as “just rerun”; record and own them.
- AI generates hypotheses from logs and comparisons; evidence and people confirm and decide.
What’s Next?
A pipeline that works reliably is an asset with running costs. Next, we look at the infrastructure and pipeline as a system to optimize: cost, performance, capacity, and waste, without trading away reliability.