We’re experiencing QUALITY GATE STATUS: FAILED error when running an analysis on a new branch on Sonar Cloud. The analysis run should create the branch and publish the result, this is not happening.
The first failed run actually creates the branch with no analysis run inside, re-executing the pipeline leads to a successful result since, after the first execution, the branch exists.
There is no actual way to create the branch before analysis using Rest APIs or similar from the pipeline, what should we do to avoid pipeline re-execution when a given branch does not still exist?
Error observed:
When the branch my_branch does not exist on the Sonar Cloud Project, the execution of the above steps results in branch creation and Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.11.0.3922:sonar (default-cli) on project demo: QUALITY GATE STATUS: FAILED is thrown. Subsequent executions will be successful.
What’s the project-level default for the New Code Definition? Is it using a reference branch (e.g. main) or some other reference point?
What do you see in the SonarCloud UI when a branch is in this state? I’m wondering if the Quality Gate status is actually “Not Computed”, and that’s being returned (wrongly, obvs) as FAILED by this particular call.
Currently, the New Code Definition is based on Previous version. The UI states “Any code that has changed since the previous version is considered new code.Recommended for projects following regular versions or releases”.
The status of the branch in this situation is “none”. The branch appears as not analyzed yet and the analysis is in error.
I guess you are using the property sonar.qualitygate.wait=true to make your CI pipeline fails in case of a red quality gate.
I was able to reproduce that on the first analysis of a branch, the quality gate is not computed, and so the status is “NONE” in the UI. We are considering this a reason to fail the scanner, to detect a later misconfiguration of the quality gate or clean code period.
I agree this is not a great user experience for the first analysis of a new branch.
I have created a ticket, but I am not sure when it will be tackled.
In the meantime, I suggest you remove the sonar.qualitygate.wait=true for the first analysis and only add it a bit later, when your branch already has some successful analyses.