The Sonar Cloud line count logic seems to have changed overnight. All of our builds are now failing with this.
##[error][ERROR] SonarQube Cloud: Error while executing task Publish: Task failed with status FAILED, Error message: This analysis will make your organization 'MyOrganization' to reach the maximum allowed lines limit (having 330636 lines).
The last successful analysis had us around 198K and there have only been a couple commits since then with far less than 1000 lines of code.
This is essentially brought our development and release to a halt and is very frustrating. Can you please advise how we can the analyzer to correctly count the lines again.
Thank you.
P.S.
The analyzed code primarily C# (ASP.NET CORE and Blazor).
Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!
We haven’t deployed any .NET-related changes in a while. There were recent deployments for (limiting the list to what might be relevant) IaC and Text/Secrets.
Is it possible your analysis scope expanded to include generated code? Or that you reclassified a project from test code to main code? Note that we auto-detect some tests (which don’t count toward LOC) based on dependencies, so if a project dropped a test-related dependency, that could cause it to be suddenly recognized as main code.
This started happening after merging a PR that cleaned up some unit tests and added additional helpers. No new unit tests were created. One new Nuget package was added to the test project which uses xunit. Other than that no major changes to the project structure.
Our PR builds don’t seem to run into this error, just the main build. I’m not sure if this is by design or a symptom of the underlying problem.
I will go ahead and do that but I don’t really have a way to get a delta between my previous runs because debug logging would not have been enabled for those runs. Based on the post I referenced it seems like there is a change to the scanner that may have caused this. Is this going to be investigated on your side? Even if we can identify what files have been added, the root cause seems to caused by a change to the sonar product. Thanks.
I created a long running branch from the last main commit that was successfully built and published without this error. When I ran my build the new branch with the exact same code that did not display this error now fails.
Output from the original successful run on 12/4
[INFO] SonarQube Cloud: Server version: 8.0.0.77094
[INFO] SonarQube Cloud: Task __redacted__ completed
[INFO] SonarQube Cloud: Analysis succeeded with warning: Your code is analyzed as compatible with all Python 3 versions by default. You can get a more precise analysis by setting the exact Python version in your configuration via the parameter "sonar.python.version"
[INFO] SonarQube Cloud: Overall Quality Gate status: ok
Finishing: SonarCloudPublish
Output from the updated run on the same commit
[INFO] SonarQube Cloud: Server version: 8.0.0.77300
##[error][ERROR] SonarQube Cloud: Error while executing task Publish: Task failed with status FAILED, Error message: This analysis will make your organization 'MyOrganization' to reach the maximum allowed lines limit (having 330636 lines).
Please contact the administrator of the organization to resolve this issue.
##[error]Task failed with status FAILED, Error message: This analysis will make your organization 'MyOrganization' to reach the maximum allowed lines limit (having 330636 lines).
Please contact the administrator of the organization to resolve this issue.
Finishing: SonarCloudPublish
The sonar server version appears to have been updated between these two runs and it seems like this update may have impacted the logic for the billing line count checks.
Is it possible that you’ve bumped xUnit 2.x to the new major version version of xUnit 3.x?
Scanner for .NET 10.3 release added support to detect xUnit 3, after the library went through backward incompatible changes that affected automatic project type detection.
Please note that we can’t see your logs, so our abilities are limited.
In case it’s a project-type (product vs test) detection issue, you can follow this document to understand how it works and what to look for in your build logs:
Please verify that all your test projects are categorized as tests.
You can also navigate your SQ project in the UI to verify if the indicated numbers of lines match your expectations. For example here, you can see that this particular project does not have any Lines of Code in the Tests folder and its underlaying projects. Edit: This probably won’t show the “new” numbers if the analysis fails.
We upgraded to xunit v3 back in April. We did have some problems with coverage stats changing which no one from sonar was able to help us with. See Code Coverage Dropped Greatly when switch to xUnit.v3. But the overall line count did not change. We just lived with the coverage metrics not matching those that are shown in Azure Devops from the same coverage files uploaded to sonar.
The recent test changes were not very large. We added the Respawn package and some helpers for resetting test db state and updated a handful of tests to call the reset.
It does not seem to be a project vs test detection issue as per my last post, the analysis on the previously successful branches is now failing as well. The fact that it fails with the exact same line count as the new analysis with the updated test code seems to indicate that the new lines of code added to the test project in the recent commits are not being counted. I can speculate that is because the test lines are being counted correctly and something else is off in the line of code counting logic either in the scanner or in the way the server billing checks are handled.
At this point Sonar Cloud is pretty much non functional and I’m not sure what to do? We keep having analysis metric changes that non one from sonar can seem to explain or help us with with. I understand we don’t have a dedicated support plan but sonar is offered as a commercial service and it seems that large scale metric changes should be investigated. I hope you would agree that this is a pretty big issue and someone from sonar may need to look at our logs to figure out why the change occurred as it is pretty clear this 130K line count jump is a cause of a recent change to some Sonar code. Thanks.
In the process of looking at it. Sorry I checked and replied to this thread before looking at the other thread. I’ll let you know the results. Thanks.
The addition of the JSON and YAML file was the root cause of this. I have added the necessary exclusions to my config and my line counts are back to the baseline. I marked the post with the reference to this information as the solution. Thanks again for all your help getting this resolved!