Codacy CLI on Windows in two simple steps

Hélio Rocha
3 min readSep 6, 2019

If you belong to the development world, for sure you have heard about Static Code Analysis tools. The best is, of course, Codacy (yes, I’m a Solutions Engineer there 😇).

Codacy offers a CLI tool that performs analysis on the code before commiting. The tool is pretty well documented but I’ve seen some people struggling to make it run on Windows environments, so here’s a little tutorial for that.

Step 1 — The Pledge (Pre-Requisites)

The magician shows you something ordinary: a deck of cards, a bird or a man. He shows you this object. Perhaps he asks you to inspect it to see if it is indeed real, unaltered, normal. But of course… it probably isn’t.

Since the tool is Docker based, you’ll need to have Docker installed. It can be found here. After the installation, don’t forget to add the drive where you have your code to “Shared Drives” on Docker so that it can be mounted by the containers performing the analysis.

2 — The Turn

The magician takes the ordinary something and makes it do something extraordinary. Now you’re looking for the secret…

I’m becoming a very big fan of the new Windows Terminal, you can find it on Microsoft Store or on GitHub. Either way, you can use whatever terminal you prefer. The command to run the Codacy CLI is the following:

docker run --rm ^
--env CODACY_CODE="/C/Path/To/Your/Code" ^
--env CODACY_PROJECT_TOKEN="YOUR_PROJECT_TOKEN" ^
--env CODACY_API_TOKEN="YOUR_API_TOKEN" ^
--env CODACY_API_BASE_URL="YOUR_INSTANCE_URL" ^
--volume /var/run/docker.sock:/var/run/docker.sock ^
--volume /C/Path/To/Your/Code:/C/Path/To/Your/Code ^
--volume /tmp:/tmp ^
codacy/codacy-analysis-cli:stable analyze ^
--directory /C/Path/To/Your/Code --format json

Please keep in mind that the paths should be *nix. This means that C:\dev\project becomes /C/dev/project.

The Prestige

But you wouldn’t clap yet. Because making something disappear isn’t enough; you have to bring it back. That’s why every magic trick has a third act, the hardest part, the part we call “The Prestige”

Sorry to disappoint but… no hardest part at all! That’s just it. It’s simple, right? You can now use Codacy CLI on your Windows environment and check the quality of your code before committing.

--

--