5/5 - (1 vote)

SonarQube is an open-source continuous quality assurance platform that supports a wide variety of programming languages ​​and provides reports on metrics such as code duplication, coding standards compliance, test coverage, code complexity, potential bugs, and more. SonarQube conveniently visualizes the analysis results and allows you to track the dynamics of project development over time.

Task: To show developers the status of source code quality control in SonarQube.

There are two ways to solve it:

  • Run the script to check the quality control status of the source code in SonarQube. If the quality control of the source code in SonarQube fails, then the assembly should be filed.
  • Show source code QC status on the project home page.

Installation of SonarQube

To install SonarQube from rpm packages, we will use the repository https://harbottle.gitlab.io/harbottle-main.

Install the repository package for CentOS 7.

Install SonarQube itself.

Most plugins will be installed during installation, but you need to install findbugs and pmd

Start the service and add it to autoloading

If it takes a long time to load, then add a random number generator /dev/./urandom to the end of the sonar.web.javaOpts options

Run the script to check the quality control status of the source code in SonarQube.

Unfortunately, the sonar-break-maven-plugin hasn’t been updated for a long time. Therefore, we will write our own script.

For testing, we will use the repository https://github.com/uweplonus/spotbugs-examples.

Import to Gitlab. Add the .gitlab-ci.yml file:

The .gitlab-ci.yml file is not perfect. It was tested if Sonarqube scan tasks ended with status: “SUCCESS”. So far, there have been no other statuses. As for the other statuses, I’ll fix .gitlab-ci.yml in this post.

Displaying source code QC status on the project home page

Install the plugin for SonarQube

  • Go to SonarQube at
  • Create a regular user, for example “badges”.
  • Go under this username in SonarQube.

Go to “My account”, create a new toker, for example, with the name “read_all_repository” and click “Genereate”.

We see that a token has appeared. It will only appear once.

  • Enter as an administrator
  • Configuration -> SVG Badges

Copy this token into the “Activity badge token” field and click the save button.

  • Go to Administration -> Security -> Permission Templates -> Default template (and other templates that you will have).
  • The user “Badges” must check the “Browse” checkbox.
  • Testing.

Let’s take the project https://github.com/jitpack/maven-simple as an example.

  • We import this project.
  • Add the .gitlab-ci.yml file to the root of the project with the following content.


In SonarQube, the project will look like this:

Add bages to README.md and they will look like this:

The badges display code looks like this:

Parsing the badges display string:

Where to get / check the Project Key and project id.

All pull requests for improvement, bug fixes etc, you can send to us or comment on this post.