Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube Leak Period between Branches or Projects

I am currently introducing SonarQube into a large legacy project. This means that there are already hundreds of warnings, in the first step I would like to ensure that there are no new warnings coming from our feature branches.

To achieve this, I want to have the Sonar analysis run on every feature branch, compare it to the main branch and alert the committer in case new warnings have been introduced.

Assume the following situation:

MyProject 1.0-SNAPSHOT is the name and version of the project on SonarQube. It has 100 warnings. It represents the develop branch. The leak period is the analysis from 1 day ago. This works very well, I can see which new warnings have been introduced since yesterday.

Developers are working on feature/somefeature branches. When they open a pull request, I want a Sonar analysis to run on that branch. This works fine, but I can't set the leak version to MyProject 1.0-SNAPSHOT from yesterday, because this branch is seen as a completely separate project by SonarQube, even though I set the sonar.projectKey to the same name and I have also tried playing around with the sonar.branch property.

The desired outcome is:

  1. develop -> 100 warnings

  2. feature/somefeature -> 102 warnings

  3. On the SonarQube dashboard of feature/somefature display "2 new warnings".

Can it be done with sonar itself, or do I need to write my own program using the Sonar REST API?

like image 459
enp4yne Avatar asked Nov 23 '17 15:11

enp4yne


People also ask

What is leak period in SonarQube?

Shortly, leak period is time frame (usually since last release), where specified criteria are measured on newly added code. This allows to focus on quality of fresh code and stop the accumulation of technical debt.

How do you analyze Branches in SonarQube?

Enabling branch analysis is as simple as setting an additional property to be passed to the SonarQube server during analysis. Unsurprisingly, the parameter's value should be name of the branch for which you're doing analysis e.g. master, my-awesome-feature.

What are the limitations of SonarQube?

Hi, Sonar, generally scans for 1 language and rules and the gate is set for that language. Having multiple language rule and gate is limitation of Sonar.

What is new code period in SonarQube?

That means that any line of code added or updated within the last 30 days is considered "new" and thus, "in the leak period".


1 Answers

You should use Branch Plugin in order to analyse branches for only new issues. This plugin has a corresponding Quality Gate:

For short-lived branches, there is a kind of hard-coded quality gate focusing only on new issues.

It will create Issues only if there are new bugs or vulnerabilities.

As per the plugin documentation all your feature branches should be identified as short-lived branches.

NOTE: Branch Plugin is licensed under SonarSource and is available in nonfree Developer Edition

like image 90
Boris Avatar answered Oct 04 '22 00:10

Boris