How to Add Codacy to Your CI Pipeline Step by Step
If your team already runs CI, you do not want a separate quality dashboard to check by hand. You want Codacy’s analysis to run inside the pipeline and fail the build when a threshold is crossed. That is what the Codacy CI integration does.
This guide covers running the analysis in GitHub Actions, uploading coverage, and enforcing rules via a config file.
Why run Codacy in CI instead of only in the dashboard?
Because the dashboard is a place people forget to open. In CI, the result is a status next to the build the developer already watches — and it can block a merge. Running it in CI also lets you pass your own test-coverage report, which sharpens the analysis. The Codacy CLI is what makes this possible outside their hosted runner.
How do I run Codacy in GitHub Actions?
- Add your project API token as a repository secret.
- Add a workflow step that runs the Codacy analysis CLI.
- Enable the coverage flag and point it at your coverage file.
- Require the resulting check in branch protection.
- name: Run Codacy Analysis
uses: codacy/codacy-analysis-cli-action@master
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
upload: true
Swap upload: true for a local-only run if you just want the exit code. Local mode skips sending code to their servers, which matters for teams with strict data rules.
How do I upload code coverage?
Generate a coverage report in your test step (an lcov file from most coverage tools), then pass its path to the Codacy action. With coverage attached, Codacy can show untested new code and flag PRs that reduce overall coverage. Without it, you only get static analysis. Do this in the same job so the file exists on disk.
How do I customize the rules with a config file?
Commit a .codacy.yaml at the repo root to control what runs per language and which paths to exclude.
exclude_paths:
- "migrations/**"
- "**/*.min.js"
engines:
pylint:
enabled: true
The biggest win here is excluding generated code and migrations. Analyzing auto-generated files produces a wall of false positives that trains your team to ignore the tool.
Codacy gate vs a pre-commit hook
| Aspect | Codacy in CI | Pre-commit hook |
|---|---|---|
| Speed | Slower, full analysis | Instant, local |
| Coverage | Multiple languages | One or two linters |
| Enforcement | Blocks merge | Bypassable with –no-verify |
| Setup | Needs CI config | One-time install |
They complement each other. The hook catches it before you commit; CI catches what slips through. Do not rely on the hook alone — developers routinely bypass it when in a hurry.
What are the gotchas?
Coverage uploads fail silently if the file path is wrong, so assert the file exists before the upload step. Analysis time grows with repo size; on a large monorepo, scope the run to changed paths to keep the pipeline under a few minutes. And every rule you enable is a future argument — start narrow, add rules only when the team agrees, or the first week turns into a noise fight.
Quick Summary
- Run Codacy in CI so results block merges instead of sitting in a forgotten dashboard.
- Use the analysis CLI action and upload your coverage file in the same job.
- Commit
.codacy.yamlto exclude generated code and control engines. - Pair with a pre-commit hook; start with narrow rules to avoid false-positive fatigue.
