Sonarqube analysis success,Quality gte failed

Hi,

From the Jenkins build output of the pipeline job,sonar analysis is showing as success but quality gate is failed.
I tried working with different options but I am getting the same error.

Below is the pipeline script I used:
My code is checkout on a linux machine and I am using unstash to get the files to my windows node

stash includes: '**', name: 'work'
node('Windows-Node') {
unstash 'work'
                  stage ('Build + SonarQube Analysis') {
                   if (enableQualityStage()) {
                    withSonarQubeEnv('pipeline-sonar') {
                       bat "\"${tool 'scanner'}\" begin /k:My Project Key /n:My Project Name"
                       bat "\"${tool 'MSBuild'}\" My Project.sln /t:Build /p:Configuration=Release /p:Platform=\"Any CPU\""
                       bat "\"${tool 'scanner'}\" end"
                }
        }
}
                 stage ('Quality Gate') {
                   if (enableQualityStage()) {
                   qualityGateStep()
                }
	}
}

Version of tools I used:

Sonar server : * Community Edition

  • Version 7.7 (build 23042)
    Sonar scanner for MSBuild:sonar-scanner-msbuild-4.6.2.2108-net46
    MSBuild : 16.0

Sonar scanner for MSBuild path in the node: C:\Utilities\sonar-scanner-msbuild-4.6.2.2108-net46\SonarScanner.MSBuild.exe

MSBuild path in the node: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\bin\MSBuild.exe

Error log: Checking status of SonarQube task ‘AWQLD…’ on server ‘pipeline-sonarqube’
SonarQube task ‘AWQLD…’ status is ‘IN_PROGRESS’
SonarQube task ‘AWQLD…’ status is ‘SUCCESS’
SonarQube task ‘AWQLD…’ completed. Quality gate is ‘ERROR’
[Pipeline] error
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // load
[Pipeline] }
[Pipeline] // gitlabCommitStatus
[Pipeline] updateGitlabCommitStatus
[Pipeline] addGitLabMRComment
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Quality Gate failure: ERROR
Finished: FAILURE

Saisirisha

Hi @saisirisha05,

A couple of questions:

  • does the Build + SonarQube Analysis step complete successfully, and can you see the analysis results in SonarQube?
  • what actions is the qualityGateStep performing? (I’m not familiar with the Jenkins plugin).

Hi @duncanp, Build + SonarQube Analysis completed ,below are the actions that are being performed by quality gate step and enable quality gate step

def call() {
timeout(time: 10, unit: ‘MINUTES’) {
script {
def qg = waitForQualityGate()
if (qg.status != ‘OK’) {
error “Quality Gate failure: ${qg.status}”
}
}
}
}

Enable quality gate step

def call() {
def m = ("${env.gitlabSourceBranch}" =~ /(master|develop|release)/)
assert m instanceof java.util.regex.Matcher
if(!m)
{
return false
}
else
{
return true
}
}

Analysis is successful and can be seen in sonar dashboard,below is the screenshot

Hi @saisirisha05,

It looks like your build pipeline doing exactly what it’s supposed to do. You’ve configured the Quality Gate step to fail the build if the Quality Gate is red, and that’s what is happening.

I’m not clear what behaviour you are expecting.

If you want the build to pass even if the quality gate is not ok then change the Quality Gate step in the pipeline so that it does not error i.e. something other than error “Quality Gate failure: ${qg.status}”

If the problem is that you want the Quality Gate to not be red, then you need to either investigate why the code coverage is zero, or remove the Coverage condition from the Quality Gate.

1 Like

@duncanp,I want to know why the code coverage is zero, I tried finding it but I didn’t find why the coverage is zero.Could you please help me with the conditions/scenarios when would the code coverage will be showing zero.

Thanks,
Saisirisha

First things first: is your build pipeline configured to run tests and collect coverage? If not, this guide contains information on how to collect coverage using different test frameworks.

The docs for the C# plugin explain which properties you need to pass to the Scanner for MSBuild so it can locate and import the test coverage files.

1 Like

@duncanp, yes,my build pipeline is configured to run tests and collect coverage.I will go through the document and try to fix the pipeline.I will test the build and let you know the results.Thank you for your time.

Thanks,
Saisirisha

@duncanp, I found an issue with the unit test case,this might be the reason with the code coverage being zero percentage.Developers are working on it.Need to test the build once the unit test is fixed.

Thanks,
Saisirisha