Setup the Codacy Analysis CLI
Follow the installation guide to get the codacy-analysis-cli executable running on your build server.
Running an analysis with the CLI
At the moment, the CLI still requires to retrieve the configuration from Codacy to perform an analysis. In order to access the project, you will have to obtain a Project Token as explained in the CLI documentation. Then, you can invoke the CLI to get a report with all the issues:
codacy-analysis-cli analyse --directory <SOURCE-CODE-PATH> --project-token <PROJECT-TOKEN> --allow-network --codacy-api-base-url <API-BASE-URL>
If you don't specify the tool, the analysis will run as Codacy does in the backend. For specific results, you can pass it with --tool.
You can see the available tools with:
codacy-analysis-cli analyse --help
There is an additional step to go through if you are using Codacy Enterprise.
Please configure the endpoint where Codacy enterprise is running either by using the flag
--codacy-api-base-url or the environment variable
For advanced configuration details, check all the CLI flags in the CLI documentation.
Some flags you might be interested in:
--allow-network - to run the tools that require compilation like SpotBugs, FindBugs, FindSecBugs
--max-allowed-issues - returns a non-zero exit code when a certain number of issues is exceeded
--fail-if-incomplete - to return a non-zero exit code when any tool fails to run successfully
Since end of June 2019, starting with SpotBugs, Codacy Enterprise version will allow the user to compile the code in their build server, then run the tool over the compilation results and send these results to Codacy.
The pushing results feature need several changes:
- Enable Run analysis through build server in the project settings in tab General section Project analysis.
- Generate a Project API token in the project settings in tab Integrations.
- Add `--upload` flag, `--project-token <PROJECT-TOKEN>` and `--codacy-api-base-url <API-BASE-URL>` to the codacy-analysis-cli command.
If you have ignored issues on Codacy be aware that the CLI will not respect those ignores when printing the results locally.
When uploading results in Enterprise the ignores will be reflected on Codacy after the analysis is complete.
Please keep in mind the CLI is still in ongoing development and the APIs it uses might be broken without notice.
If you run into issues or have any questions, please don't hesitate to reach out at firstname.lastname@example.org.