Triggering new analysis from CI

We support analysis trigger from your continuous integration job. This is very simple to put in place and we use a generic method that can be adapted to most CI environment.

Installing the CI tools

Our CI tools are distributed using PyPi. You can install them using the following command:

pip install code-inspector

Using the CI tools

Setting your API keys

In order to use the CI tool, you need to set up two environment variables that identifies you are as user: CODE_INSPECTOR_ACCESS_KEY and CODE_INSPECTOR_SECRET_KEY.

You can get these keys from the web interface, in your user preferences.

Important Note: these API keys identify you as a user and not as a project. Actions you can perform are limited by your user permissions.

Deprecation: early versions of code-inspector uses API key per-project. These keys are no longer working and the REST API that was using them is deprecated in favor of our new GraphQL API.

Trigger an Analysis

To trigger an analysis (and potentially get results from it), use the binary code-inspector-analyze.

If you pass the -w flag to the code-inspector binary, the program will produce the results of the analysis, with the number of violations, duplicates as well as the number of violations per language.

If you are working with a large project that takes time to analyze, you might need to increase the timeout to get the analysis results using the -t flag. This flag defines the value of the timeout (in seconds) before getting the analysis results.

For example, the following line will trigger a new analysis, wait at most 20 minutes to get the analysis results and then print the results:

code-inspector-analyze -t 1200 -w -p "MY-AWESOME-PROJECT"

Compare a project status with another branch

Sometimes, you want to compare the status of your project with another repository or just another branch. The program code-inspector-compare is the one you want to use in that case.

The project compares your project against another codebase hosted on another repository. You can specify a revision (flag --target-revision) or specific branch (--target-branch) to compare against.

You can also use your Github/Gitlab or Bitbucket credentials to checkout the target repository (flag --kind).

You can use it as follow:

code-inspector-compare -t 1200 -w -p "MY-AWESOME-PROJECT" --url https://path/to/other/repository.git --target-branch development --kind Github

This will then start a comparison of MY-AWESOME-PROJECT on code inspector with the code on the repository https://path/to/other/repository.git on the developmentbranch. To checkout the target repository, the Github credentials of the authenticated user are used.

Integration with GitLab Continuous Integration

Mike Atkinson (@MikeGAtkinson) from (JHCTechnology)[https://twitter.com/JHCTechnology] developed a docker image that can be used to integrate code inspector in your GitLab CI pipeline.

The project is available on GitLab: https://gitlab.com/jhctechnology/code-quality/code-inspector

Get your project badge

You can show a badge on your project page to show the code grade (as shown below).

Example of badge

Insert a link to an image like this (replace <PROJECT_IDENTIFIER> by your project identifier).

[![Code Grade](https://www.code-inspector.com/project/<PROJECT_IDENTIFIER>/status/svg)](https://www.code-inspector.com)

More information and contributing

For more information about the tool used for continuous integration, you can look at the related github project.