Sonar Cloud - Quality Gate failure

Hi Team,
Have integrated AWS Codepipeline with SonarCloud and every time i trigger build through AWS codepipeline for short-lived branches. Noticed it throw Quality Gate failed message in SonarCloud Dashboard for my project.

Can anyone please help me that what causing this issue and how i can passed this message.

Here is snapshot for reference.

I am generating one json file to check the status of quality gate and everytime build is ended up with following output… Is this culprit because of which am not seeing passed message for Quality gate in SonarCloud dasboard?

Also, why am seeing code converge 0.00% everytime ?

curl -u $TOKEN https://sonarcloud.io/web_api/api/qualitygates/project_status?projectKey=$Project >result.json

{
“projectStatus”: {
“status”: “ERROR”,
“conditions”: [
{
“status”: “OK”,
“metricKey”: “new_reliability_rating”,
“comparator”: “GT”,
“periodIndex”: 1,
“errorThreshold”: “1”,
“actualValue”: “1”
},
{
“status”: “OK”,
“metricKey”: “new_security_rating”,
“comparator”: “GT”,
“periodIndex”: 1,
“errorThreshold”: “1”,
“actualValue”: “1”
},
{
“status”: “OK”,
“metricKey”: “new_maintainability_rating”,
“comparator”: “GT”,
“periodIndex”: 1,
“errorThreshold”: “1”,
“actualValue”: “1”
},
{
“status”: “ERROR”,
“metricKey”: “new_coverage”,
“comparator”: “LT”,
“periodIndex”: 1,
“errorThreshold”: “70”,
“actualValue”: “0.0”
},
{
“status”: “OK”,
“metricKey”: “new_duplicated_lines_density”,
“comparator”: “GT”,
“periodIndex”: 1,
“errorThreshold”: “50”,
“actualValue”: “11.775043936731107”
},
{
“status”: “OK”,
“metricKey”: “new_security_hotspots_reviewed”,
“comparator”: “LT”,
“periodIndex”: 1,
“errorThreshold”: “100”,
“actualValue”: “100.0”
}
],
“periods”: [
{
“index”: 1,
“mode”: “days”,
“date”: “2021-09-14T16:24:37+0200”,
“parameter”: “30”
}
],
“ignoredConditions”: false
}
}

Hello,

I’ve got the feeling that you don’t get the concept of Quality Gate provided by SonarCloud. It is expected to get a FAILED QG each time you run a scan if you do nothing to mitigate the problems found by SonarCloud.
The Quality Gate is there to tell you if you can deliver in PROD your software. If it’s GREEN/PASSED, it means the quality (reliability, maintainability, security, coverage, …) is at the expected level. If it’s RED/FAILED, it means you need to fix problems. These problems are highlighted when you click on the name of the project. Here is an example of what you should get:

Here SonarCloud is telling me that I have some Vulnerabilities to fix on the recently changed code and I should add some tests/coverage to reach 80% of coverage by Unit Tests of the recently changed code (aka New Code).

I believe you should share a screenshot of your project home page so all can see why you have a Failed Quality Gate and you should also share your Quality Gate definition (same as a screenshot).

Alex

Note: in your case I believe you have 0% of Code Coverage because you did nothing to provide coverage data to SonarCloud. SonarCloud doesn’t measure the code coverage, it imports coverage data generated by coverage tools. It only detects when no data for a given executable lines was provided.

Thanks @Alexandre_Gigleux for your response !

You are correct on 0% of Code Coverage. I was not aware of this part and now I’m in process to import the coverage data so we can start seeing some % in SonarCloud dashboard.

Do you have any reference document that how i can import code coverage for .Net Core application in sonarcloud.

Hello Team,
Can anyone pleas help and let me know that why everytime am seeing 0% for code coverage.

Below is the snippet from logs.

/root/.nuget/packages/coverlet.msbuild/3.1.0/build/coverlet.msbuild.targets(39,5): warning : [coverlet] Unable to instrument module: /codebuild/output/src950/src/s3/00/aspnet-core/modules//test/bin/Release/net5.0/Volo.Abp.TextTemplateManagement.EntityFrameworkCore.dll because : No symbol found for file: /codebuild/output/src950/src/s3/00//aspnet-core/modules//test//bin/Release/net5.0/Volo.Abp.TextTemplateManagement.EntityFrameworkCore.dll [/codebuild/output/src950/src/s3/00//aspnet-core/modules//test/
Test run for /codebuild/output/src950/src/s3/00//modules//test//bin/Release/net5.0/ (.NETCoreApp,Version=v5.0)
Microsoft (R) Test Execution Command Line Tool Version 16.11.0
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait…
A total of 1 test files matched the specified pattern.
No test is available in /codebuild/output/src950/src/s3/00/aspnet-core/modules/test/bin/Release/net5.0/. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

Calculating coverage result…
Generating report ‘/codebuild/output/src950/src/s3/00//aspnet-core/modules//test/coverage.opencover.xml’

±--------------------------------------------±-----±-------±-------+
| Module | Line | Branch | Method |
±--------------------------------------------±-----±-------±-------+
| Domain | 0% | 0% | 0% |
±--------------------------------------------±-----±-------±-------+
|Application.Contracts | 0% | 100% | 0% |
±--------------------------------------------±-----±-------±-------+
| Domain.Tests | 0% | 100% | 0% |
±--------------------------------------------±-----±-------±-------+
| Domain.Shared | 0% | 100% | 0% |
±--------------------------------------------±-----±-------±-------+
| TestBase | 0% | 0% | 0% |
±--------------------------------------------±-----±-------±-------+
| EntityFrameworkCore.Tests | 0% | 100% | 0% |
±--------------------------------------------±-----±-------±-------+
| Application | 0% | 0% | 0% |
±--------------------------------------------±-----±-------±-------+
| Utils | 0% | 0% | 0% |
±--------------------------------------------±-----±-------±-------+
| EntityFrameworkCore.DbMigrations | 0% | 100% | 0% |
±--------------------------------------------±-----±-------±-------+
| EntityFrameworkCore | 0% | 0% | 0% |
±--------------------------------------------±-----±-------±-------+

±--------±-----±-------±-------+
| | Line | Branch | Method |
±--------±-----±-------±-------+
| Total | 0% | 0% | 0% |
±--------±-----±-------±-------+
| Average | 0% | 50% | 0% |
±--------±-----±-------±-------+

Hi Vishal,

The output you present above seems to be from the MS coverage tool itself, not SonarCloud.

I can’t help you with the details of how to set up the coverage tool, but, once you get it working, the general idea is this:

You set up your build pipeline so that, on each build:

  1. The coverage tool runs and produces a coverage report, which it outputs to some directory.

  2. SonarCloud is configured to pick up that coverage report from the directory you specify, process it, and display the data as part of its analysis results.

For details on how to configure SonarCloud, have a look here: