Prompt
How do I troubleshoot a build that works locally but fails in CI?
Latest observation
A good way to troubleshoot “works locally, fails in CI” is to assume the two environments are not actually the same and then systematically narrow down the differences.
1) Compare the environments first
Check these between local and CI:
- OS / base image
- Language/runtime versions
- Node, Python, Java, .NET, Go, Rust, etc.
- Dependency versions
- Lockfile used? Re-resolved in CI?
- Build tools
- npm/yarn/pnpm, pip/poetry, gradle/maven, cargo, make, etc.
- Environment variables / secrets
- Missing or different values in CI
- File system behavior
- Case sensitivity, path separators, permissions
- Network access
- CI may not access private registries, APIs, or git submodules
2) Make CI reproduce locally
Try to run the build in an environment as close to CI as possible:
- Use the same Docker image or runner image
- Use the same command CI runs
- Use the same environment variables
- Use a clean workspace:
- delete
node_modules, build artifacts, caches - use a fresh clone if possible
- delete
If it fails locally in that environment, you’ve already won half the battle.
3) Inspect the exact failing step
Don’t focus only on the final failure message. Look for:
- the first error
- warnings right before the failure
- any command that succeeds locally but not in CI because of shell differences
Tip: add verbose/debug flags:
npm ci --verbosepytest -vvmvn -Xgradle --info --stacktracecargo build -vv
4) Check dependency installation
A very common cause is dependency drift.
Questions to ask:
- Is CI using the lockfile exactly?
npm civsnpm installpip install -r requirements.txtvs unpinned ranges
- Are packages pulled from a different registry?
- Is there a private dependency or git submodule missing?
- Did a transitive dependency update unexpectedly?
Best practice:
- pin versions
- commit lockfiles
- avoid “latest” in CI
5) Look for case-sensitivity and path issues
CI is often Linux, while local dev may be macOS/Windows.
Common problems:
import Foovs filefoo.jssrc/Utilsvssrc/utils- hardcoded
C:\...or/Users/... - relative paths that depend on working directory
6) Check permissions and ownership
CI runners may run as a different user or with restricted permissions.
Watch for:
- writing to protected directories
- needing
chmod +xon scripts - executable bit missing in git
- temp directory access
- bind-mounted volume permissions in Docker
7) Review environment variables and secrets
A build can fail if CI lacks:
- API keys
- feature flags
- proxy settings
- custom registry credentials
HOME,CI,NODE_ENV,PATH
Make sure secrets are:
- actually configured
- available to the right job/stage
- not accidentally masked or expired
8) Check shell and scripting differences
CI may use a different shell than your local terminal.
Examples:
bashvssh- PowerShell vs cmd.exe
- multiline command quoting differences
set -ebehavior- pipefail not enabled
Make scripts explicit about the shell they expect.
9) Eliminate cache issues
CI caches can cause confusing behavior.
Try:
- disabling cache once
- clearing dependency caches
- rebuilding from scratch
- invalidating Docker layers if needed
If the build passes after cache clear, the problem may be stale artifacts or mismatched cache keys.
10) Add logging and artifacts
If the failure is hard to reproduce:
- print versions:
node -v,python --version,java -version
- print working directory and environment
- upload logs and build artifacts
- save intermediate outputs
- capture test reports, coverage, and stack traces
11) Minimize the problem
Reduce the build to the smallest failing case:
- one test
- one module/package
- one build target
- one dependency
This often reveals the issue quickly.
12) Common root causes checklist
Here’s a quick checklist of frequent culprits:
- Different language/runtime version
- Missing lockfile or dependency drift
- Case-sensitive file path issue
- Missing env var or secret
- Permission/executable-bit issue
- Hidden assumption about working directory
- CI uses clean checkout, local uses stale files
- Cache corruption or stale artifacts
- Network/private registry access problem
- OS-specific behavior
- Shell quoting/command syntax difference
Practical debugging pattern
A reliable workflow is:
- Copy the CI command locally
- Run it in a clean environment
- Add verbose logs
- Compare versions and env vars
- Remove caching
- Minimize until the failure is obvious
If you want, I can also give you:
- a CI troubleshooting checklist template
- specific steps for GitHub Actions / GitLab CI / Jenkins
- or help debug a specific error log if you paste it here.