which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
SonarQube: 9.9.1 Enterprise LTS
GitHub:
sonarsource/sonarqube-scan-action@master
sonarsource/sonarqube-quality-gate-action@master
Bamboo:
Sonar plugin 2.10.1
SonarScanner 4.8
how is SonarQube deployed: zip
what are you trying to achieve: I want to get the same scan result in GitHub as we did before in Bamboo
what have you tried so far to achieve this: I tried playing around with the sonar.branch.name and sonar.projectVersion properties in the sonar-project.properties file.
The problem:
Scanning the develop branch (main branch) in Bamboo returns the expected result. I assume it is a full scan and not a diff scan. It takes about an hour.
In SonarQube I see on the main project page: New Code since 9/11/2022, started one year ago.
I see also an activity graph with issues. This graphs remains steady and predictable when scanning with Bamboo
We are migrating to GitHub and when I scan the develop branch, the nr of issues goes to 0. Also the acticvity graph goes to 0 for that analysis. So there is a difference between a scan in Bamboo and GitHub. We can to keep track of our issues.
My guess is in GitHub we somehow scan as a PR and only check the diffs? I tried multiple things, but cant get it to work as we would like.
I already cleaned up alot of deprecated/legacy properties in our sonar-project.properties file. But maybe there is more legacy causing this issue.
Any help is appreciated. If you need more information or details, please ask.
A good starting point would be to produce DEBUG logs (sonar-scanner -X) of the runs in Bamboo and GitHub and start looking for obvious differences. You can also share them here.
The logs basically look the same (files indexed) except that your Bamboo analysis wasnât able to make use of an analysis cache.
Bamboo:
|build|08-Nov-2024 09:08:40|INFO: Starting batch processing.|
|build|08-Nov-2024 09:08:41|INFO: The Java analyzer cannot skip unchanged files in this context. A full analysis is performed for all files.|
GitHub
2024-11-08T08:58:29.3534434Z 08:58:29.353 INFO Server-side caching is enabled. The Java analyzer was able to leverage cached data from previous analyses for 17854 out of 17858 files. These files will not be parsed.`
Can you share a screenshot of what youâre seeing in SonarQube after performing the analysis of the develop branch in GitHub?
Basically this graph drops to 0 when having scanned via GitHub. I removed most (incorrect) scans from the past. Leaving only a few for illustration. One on the right is from today, but hard to see on the graph.
sonar.analysisCache.enabled=false increases the scan time considerably, even for PRâs. I know this is normal. Yes, I can work around it by making my workflow action dynamic (which I have done already). But I would expect that the scanner detects branch vs PR scan and by default sets the correct values in the background, no?
Is there no option to only scan for the differences on a branch scan AND keep the issue history? I know we set a project version in the past and it is something I try to remove without losing history. But might the project version from 2 years ago be the culprit here?
Any other things I should do to make this just work as expected without all the config properties?
Just to confirm â does setting sonar.java.skipUnchanged=false and -Dsonar.analysisCache.enabled=true (alternatively, not setting sonar.analysisCache.enabled) a working combination?
If so, next weâll dig into why sonar.java.skipUnchanged is affecting the analysis results. It should only speed it up, not remove issues.
This is the goal of sonar.java.skipUnchanged and the analysis cache.
Based on the tests we ran, it indeed seems like sonar.java.skipUnchanged is the root cause.
My guess it only takes into account the issues from the scanned files. If there are just few files with no (new) issues it will be reported as such.
It feels like it is treated as a PR diff scan, which also only reports new issues for the changed files, not the complete history of the complete project.
Where as what I try to do here is a full branch scan. In this case I expect to keep the history and add/remove issues. Likely these issues already updated in the project by the PR scan that came before.
If you like to see more of the log, Im happy to provide it. Or other SQ server/project settings.
My understanding of sonar.java.skipUnchanged is that it should only be applied in a PR context.
Howâs your build time looking now?
Can you share your full GitHub Actions YML file?
Iâd like to pass this on to some expert eyes who understand the mechanism better â however, be aware they have quite a backlog at the moment. Iâm hoping your build time is back as expected and at least for now, you can live with the setting (even though it should be unnecessary).
For Java analysis, please note that the skipUnchanged parameter cannot be enabled for branch analysis; otherwise, the issue youâre experiencing is expected. The cacheâs goal is to make PR analysis faster; however, for branch analysis, we always perform a full scan.
To summarize, correct me if I am wrong: You moved your CI from Bamboo to GitHub, and in branch analysis, the skipUnchanged parameter was set to true without you explicitly configuring it, leading to the reported issue. Hardcoding skipUnchanged to false is a good workaround for now. You should not need to adjust the cache parameter, and it would be better not to do so. I will assign this issue to the team responsible for the integration with GitHub.
One last question: It seems the cache is working for PR analysis. Are you experiencing the performance you were expecting in that context?
Question
You moved your CI from Bamboo to GitHub, and in branch analysis, the skipUnchanged parameter was set to true without you explicitly configuring it, leading to the reported issue. Answer
Correct
Question
Hardcoding skipUnchanged to false is a good workaround for now. Answer
Not really hard coded. Dynamic based on GitHub variable check. Default GitHub workflow functionality:
-Dsonar.analysisCache.enabled=${{ github.event_name == âpull_requestâ }}
Statement
I will assign this issue to the team responsible for the integration with GitHub.
=> Great! Either implement the logic inside the action or update the documentation to configure the property in the workflow like I have.
Question
It seems the cache is working for PR analysis. Are you experiencing the performance you were expecting in that context? Answer
Everything is relative. About 10 minutes for a PR scan, which is fast enough for us.
In the past with java8 the cache didnât seem to work properly and we had scan times of 30-60 minutes for a PR. After moving to java17, this issue was magically fixed. See my previous topics about this issue.
The full branch scan takes about 1 hour for 3 million lines of code. As we are not actively waiting on the branch scan, this is again fast enough for us.
PR scan times are what matter to us.
=> Performance is meeting expectations.