When I say "new code",I mean that compare two commits in master branch and get the new code. I am confused about the new code coverage in sonarqube.I want to specify the comparison of two commitIDs
Asked
Active
Viewed 6,671 times
1 Answers
0
Check in the analysis parameters if the sonar.projectDate
one can help:
- Retrieve the oldest version of your application's source that you wish to populate into the history (from a specific tag, whatever).
- Run a SonarQube analysis on this project by setting the sonar.projectDate property. Example: sonar-scanner -Dsonar.projectDate=2010-12-01
- Retrieve the next version of the source code of your application, update the sonar.projectDate property, and run another analysis. And so on for all the versions of your application you're interested in.
If your commits are done on different days, that could work.
This is not as precise as two commits ID, but can still help here.
See "SonarQube - unity tests code coverage on new code not working" (if this has not changed since SonarQube 5.x)

VonC
- 1,262,500
- 529
- 4,410
- 5,250
-
I can not run two times in one day, otherwise sonarqube tells me that Validation of project failed: o Date of analysis cannot be older than the date of the last known analysis on this project. Value: "2018-04-12T00:00:00+0800". Latest analysis: "2018-04-12T00:00:00+0800". It's only possible to rebuild the past in a chronological order. – Sherry Apr 12 '18 at 05:52
-
@Sherry yes, that is what I meant by "If your commits are done on different days, that could work." – VonC Apr 12 '18 at 06:02
-
@Sherry If not (meaning your old and new commits are from the same date), I would suggest publish (call) Sonar with a *new* project name, based on your old commit, then call it again on that new Sonar project with your newer commit ID. – VonC Apr 12 '18 at 06:03
-
We have multiple developers working on one project.If the . If developerA merged his branch into master branch on 2018-04-10 ,then A gets his new code coverage 15% which failed to reach the standard.We ask him to write more unit tests. Developer B merged his branch into master branch on 2018-04-11,then B gets his new code coverage 75% which reach the standard. Then on 2018-04-12,developer A merged his branch into master again.which are "new codes"? – Sherry Apr 12 '18 at 06:03
-
@Sherry for new code specific to a feature branch, developerA might consider pushing that branch first, as done in https://github.com/gabrie-allaigre/sonar-gitlab-plugin/issues/75. – VonC Apr 12 '18 at 06:09