SonarQube Coverage report with Jenkins Pipeline

Hello Team,

i am working on get the Coverage SQ reporting on my dashboard, using Jenkins pipeline.
the configuration I have is the following:

stage(‘SonarQube Scan’){
steps{
script{
sonarHome = tool ‘sonar.isolutions.ds’
}
withSonarQubeEnv(‘sonar.isolutions.ds’) {

                        sh "${sonarHome}/bin/sonar-runner -Dsonar.host.url=http://sonar.isolutions.ds/sonar -Dsonar.projectKey=${sonar_project} -Dsonar.projectName=${sonar_project} -Dsonar.projectVersion=${FULL_VERSION_STRING} -Dsonar.sources='${WORKSPACE}/src-webapp/src' -Dsonar.java.binaries='${WORKSPACE}/build/libs' -Dsonar.exclusions='${WORKSPACE}/src, ${WORKSPACE}/src-webapp/node_modules/**/*, ${WORKSPACE}/src-webapp/dist/**/*, **/*.spec.ts, **/*test.ts, **/*.js, **/*.css, **/*.scss' -Dsonar.test.inclusions='**/*.spec.ts,**/*test.ts' -Dsonar.tests='${WORKSPACE}/src/test' -Dsonar.coverage.jacoco.xmlReportPaths='${WORKSPACE}/build/reports/jacoco/test'"
                    }
                }
            }

The coverage just doesn’t work, the result is 0%
Is there something missing in my pipeline? the XML file I have already generated with gradle and the PATH is correct, which is: Dsonar.coverage.jacoco.xmlReportPaths=’${WORKSPACE}/build/reports/jacoco/test

i dont know what is missing…

Thanks for your support,

Hi,

Welcome to the community!

First, it would be helpful to provide your code formatted (``` on the line before and on the line after) analysis logs. Second, you seem to be analyzing Java. What’s your build technology? If it’s Maven or, as I suspect, Gradle, your life will be made easier by using the dedicated scanner. You certainly won’t have to specify as much on the command line.

 
HTH,
Ann

Hi Ann,
This is the stage Build from my jenkins File, and its located above of my sonarQube Scan posted above.

stage(‘Build’){
steps{
sh(script: ‘./gradlew -Pminify build’)
sh(script: ‘./gradlew build jacocoTestReport sonarqube’)
sh(script: ‘./gradlew jacocoTestReport’)
}
}

I’ve got my build.gradle configured as you can see below.
But i dont know what is missing on my Jenkins file or my build.gradle:

these are the most relevant configuration on my Build.gradle regarding Jacoco and Coverage report on Sonarqube. But its still in 0% i really dont know what to do, 4 days checking and i am stucked… (

Build.gradle:

plugins {
id ‘org.springframework.boot’ version ‘2.3.2.RELEASE’
id ‘io.spring.dependency-management’ version ‘1.0.9.RELEASE’
id ‘java’
id “com.github.node-gradle.node” version “2.2.4”
id ‘jacoco’
id ‘com.github.sherter.google-java-format’ version ‘0.9’
id ‘org.sonarqube’ version ‘3.0’
}

test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

jacocoTestReport {

reports {
    xml.enabled true
    // csv.enabled false ---> commented
    // html.destination file("${buildDir}/jacocoHtml")  ---> commented
    // xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")  ---> commented
}

}

task npmBuildDev(type: NpmTask) {
dependsOn ‘npmInstall’
execOverrides {
it.workingDir = ‘src-webapp’
}
args = [‘run’, ‘build’]
}

task npmBuildProd(type: NpmTask) {
dependsOn ‘npmInstall’
execOverrides {
it.workingDir = ‘src-webapp’
}

args = ['run', 'build:prod']

}

sonarqube {
properties {

    property 'sonar.projectName', 'CFDM'
    property 'sonar.host.url', 'http://sonar.isolutions.ds/sonar'
    property 'sonar.projectKey', 'CFDM'
    property 'sonar.sources', 'src/main, src-webapp/src'
    property 'sonar.tests', 'src/test'
    property 'sonar.exclusions', 'src-webapp/node_modules/**/*, src-webapp/dist/**/*, **/*.spec.ts, **/*test.ts, **/*.js, **/*.css, **/*.scss'
    property 'sonar.test.inclusions', '**/*.spec.ts,**/*test.ts'
    property 'sonar.java.libraries', 'build/libs'
    property 'sonar.java.binaries', 'build/classes'
    property 'sonar.coverage.jacoco.xmlReportPaths',"${buildDir}/reports/jacoco/test/jacocoTestReport.xml"

}

}