Issue importing CodeCoverage to SonarQube using Jenkins Pipeline

Using SonarQube Version 6.7.7 (build 38951)

Cannot upload the CodeCoverage result to SonarQube. The Unit Tests appear (along the static analysis result) but codecoverage remains 0%

The Unit Testing is made in Jenkins and is successful according to the Jenkins Console but no coveragexml file is generated…

pipeline {
  agent none
      agent {
        label 'Miguel'
      steps {
        checkout scm

stage('Static Analysis'){
  agent {
    label 'Miguel'
  steps {
    script {
      echo "Starting Static Analysis Stage"
      def msbuild = tool name: 'MSBuildMiguel', type: 'hudson.plugins.msbuild.MsBuildInstallation'
      def sonarHome = tool 'MSBuildSonarScannerMiguel'
      def vstest = tool 'vstestMiguel'
      def codecoverage = tool 'codecoverageMiguel'
        bat """
          ${sonarHome}/SonarScanner.MSBuild.exe begin /k:com.SecurityUtilities /n:TTSecurity /v:1.0 /d:sonar.cs.vstest.reportsPaths=**/*.trx /d:sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml
          ${msbuild} TTSecurity.sln /t:Rebuild
          ${vstest} /Logger:trx "TTSecurityTests\\bin\\Release\\TTSecurityTests.dll" 

          ${codecoverage} analyze /output:d:**.coveragexml  d:**.coverage

          ${sonarHome}/SonarScanner.MSBuild.exe end

} }

The Unit Testing is done:

Starting test execution, please wait…


Results File: C:\Users\FNM1AV\Desktop\JenkinsSlave\workspace\Security_Utilities_master\TestResults\FNM1AV_PT-N01504_2019-09-10_22_47_24.trx

Test Run Successful. Total tests: 18 Passed: 18 Total time: 1.8712 Seconds

The Jenkins Console shows:

“WARN: Could not find any coverage report file matching the pattern ‘**/*.coveragexml’.”


This is the crux of your problem:

If no coverage report is generated, there’s no way SonarQube is going to be able to report your coverage data. You need to get that coverage report generated and unfortunately that’s a bit out of the scope of this community.