Unexplainable/unreproducible new code analysis results

Hello,

we are on SonarQube Community Edition v9.9.2, which was deployed from zip.

We are facing the situation the we cannot get valid insights to an analysis result before the merge to the destination branch. We are aware that branches are not supported by SonarQube in the Community Edition. Therefore we are running each branch as a new project in SonarQube.

We have merged the latest pull request to develop and SonarQube new code analysis fails because of reported issues

Our hope was/is that we could somehow get this analysis result before we actually hit the merge button. I have there tried three different approaches:

  1. Branch reset → feature/SonarTest
  • Create a new branch on the old develop state (green “develop” in the repository screenshots)
  • Push the changes for analysis in the Jenkins pipeline to the repository
  • Reset the branch “hard” to the last commit in the pull request (the one highlighted blue in the above first screenshot)
  • Push the changes again for analysis in the Jenkins pipeline to the repository
  1. Branch reset 2 → feature/SonarTest2
  • Create a new branch on the old develop state (green “develop” in the repository screenshots)
  • Push the changes for analysis in the Jenkins pipeline to the repository
  • Reset the branch “hard” to the current origin develop branch (after the merging the PR)
  • Push the changes again for analysis in the Jenkins pipeline to the repository
  1. Merge check → feature/SonarTest3
  • Create a new branch on the old develop state (green “develop” in the repository screenshots)
  • Push the changes for analysis in the Jenkins pipeline to the repository
  • Merge the last feature branch commit into the feature branch, but create a new commit instead of using “fast-forward”
  • Push the changes again for analysis in the Jenkins pipeline to the repository

Here you can see the outcome in the repository

All of the above approaches result in below new code analysis results

which does not match the results from develop branch’s new code analysis (as you can see in comparison to the second screenshot).

My understanding is that the new code analysis compares the current code base results with the one from the last analysis. How can it be that even though we recreate the picture from the develop branch we get different results here?

Please let me know in case you need more details.

Regards,
Martin

Hi Martin,

That’s possible, but not advisable.

Actually, your screenshots tell the tale. Your failed condition is an ‘on New Code’ requirement. But look at what constitutes “new”:

Selection_1342

Selection_1343

You’re not comparing apples to apples.

And unfortunately, you’re not going to be able to since you didn’t start analyzing the feature branch 19 days ago.

 
Ann

Hi Ann,

Thanks for your explanation.

I must admit I do not understand why the analysis time should be the root cause. For all analysis, the same basis commits has been used (see marking 1. in below screenshot).

I have tried three time to recreate the result of the develop analysis 2b. I was not able to do that even with recreating the same “history”, here feature/SonarTest2. We also should keep in mind that the checked-out code for 2a, 2b and 2c is the same (all the changes that were merged to develop branch too). Therefore, a comparison against the same baseline should result in the same result, independent from the time the analysis is running. Shouldn’t it, or do I miss a point in my thought process here?

Regards,
Martin

Hi Martin,

Target branch really only matters in PR analysis, which you don’t have.

Your New Code Definitions are, respectively:

  • all the code changes since the baseline analysis 19 days ago
  • all the code changes since the baseline analysis 1 hour ago

 
Ann

Hi Ann,

maybe I was not too clear in my explanation of my confusion.

Develop branch (“SonarQube project develop branch”) had an analysis 19 days ago on “commit baseline”, now the developers merged one PR (as you can see in the first repo screenshot in this thread) which creates “commit new code” and SonarQube result was this:

I have tried to recreate the same result in multiple ways, having the same “commit baseline” as baseline and then get the new code “commit new code” analyzed. Each of my attempts was done in an own SonarQube project, but this with the same commit history as for develop, only “commit baseline” and one “commit new code”.

This means all SonarQube projects I have mentioned for develop, feature/SonarTest, feature/SonarTest2 and feature/SonarTest3 have only seen two code states, “commit baseline” and “commit new code”.

The only difference is the time of analysis, “SonarQube project develop branch” had analyzed “commit baseline” 19 days ago where all other “SonarQube project feature/SonarTest branch”, “SonarQube project feature/SonarTest2 branch” and “SonarQube project feature/SonarTest3 branch” analyzed “commit baseline” on the day I have create this support request. The content/code for all of these baseline analysis was the same, and the same goes for the “commit new code” which was the same content/code, just different “git ways” to get to it.

How can it be that I’m not able to reproduce the result when only two points (“commit baseline” and “commit new code”) are taken into consideration? Or is there more from the “SonarQube project develop branch” taken into consideration what I did not recreate in my “SonarQube project feature/SonarTest branch”?

Regards,
Martin

Hi Martin,

So you’ve analyzed 4 different “projects” (branches) each with analyses of the same 2 commit hashes.

And what shows up as “new” code in each? When you go to the Measures tab and look, for instance at New Lines, do the same files? same lines show up in each project?

 
Ann

Hi Ann,

yes, I think now we are on the same page. :grinning:

4 different projects:

  • 2 project (develop and recreation) had the same 2 commit hashes analyzed with different results, and
  • 2 additional projects with the same baseline commit (as above) and different hashes for the second analysis, but I can ensure that the code in these two hashes was the same as for the first point’s second analysis point. The results of both projects matched the “recreation project” I have made on the first point.

I had to recreate the scenario once more because our developers had already made changes to the develop branch. I used the same 2 commit hashes for analysis and there is a slight discrepancy visible.

As you can see there is a difference in the new lines as well then the coverage section. All the other sections I have checked and they are the same.

Regards,
Martin

Hi Martin,

Can you share the two analysis logs?

 
Ann

Hi Ann,

sure, this is the content of the log folder, which files do you need?

Regards,
Martin

Hi Martin,

your screenshot shows the Sonarqube server logs, but Ann asks for the analysis logs of your scanner.

Gilbert

Hi Gilbert,

okay, where do I find them? Is this maybe the log output in the Jenkins pipeline when we call “sonnarscanner end”?

Regards,
Martin

Yes, you will see the output of the Sonarqube analysis in the Jenkins console log.
For complex builds, i.e. when using the parallel step you can use the Blue Ocean view or its
successor, the pipeline explorer to get the relevant parts of the log.

It seems your using the SonarScanner for .Net and for troubleshooting you should increase the loglevel to get more details, /d:sonar.verbose=true

1 Like

Hi Gilbert,

please find attached both logs.
develop_log.txt (77.0 KB)
feature_SonarTest_log.txt (78.0 KB)

Thanks for this hing, I will keep the increase of the loglevel in mind and potentially add it to our Jenkins build library.

Let me know in case you need additionally.

Regards,
Martin

Hi Martin,

Thanks for the logs. Having looked at them… I really don’t know what to tell you.

This comes down to the detection of new code. That detection is based on SCM data. I can only guess there’s a difference in the local Git repo, but I can’t give you anything more than that.

 
:woman_shrugging:
Ann

Hi Ann,

thanks for this hint. Weird thing though is, that the same commit IDs are checkout (I verified this once more in the logs) and we always do a workspace wipe + fresh full checkout for each build. :thinking:

Would it help to get the logs with the verbose output Gilbert mentioned? I could maybe try to tweak something there.

Regards,
Martin

Hi Martin,

The topic of detection of new code is pretty complex. As I said, I suspect there’s a difference in the local Git repo. But I can only speculate, and I don’t think I’m going to spend much more time trying to help you work around buying a license.

 
:woman_shrugging:
Ann

Hi Ann,

I understand your point and indeed for us it is currently a “license workaround”. This has effect on the support from your side, I see this too.

I would consider to get the paid version of SonarQube but I’m not fully trusting that the problem is solved. I find it concerning that the application seems to be non-deterministic.

Is there a way to mitigate this concern? I would like to understand the current results better from a technical perspective and support you further in getting to the bottom if this non-deterministic behavior.

Regards,
Martin

Hi Martin,

you may do a POC with the trial version to see if it works for you !?

Gilbert

1 Like