Version:
8.1
Intent:
I am trying to report unit and integration tests coverage to SonarQube from my Java project to see the metrics for both separately on the SonarQube dashboard.
Tried so far:
I have added the maven jacoco plugin to the pom.xml in my project and configured it to generate 2 exes, jacoco-ut.exec and jacoco-it.exec.
I am trying to deal with the unit tests first since the integration tests are failing in the build for some other reason. Here is the command I use to run the unit tests in my Jenkinsfile:
stages {
stage('Build') {
agent { label "build-centos" }
environment {
branch_name = "${env.BRANCH_NAME}"
}
steps {
writeFile file: '.build-docker', text: ''
script {
initPipeline majorVersion: '4',
serviceName: 'forensics-service'
parallel (
app: {
sh """
mvn -DnewVersion=$VERSION versions:set
mvn -X -Dproject.docker.project=$DOCKER_REPO -Dsonar.host.url=*** -Dsonar.login=*** -
Dsonar.password=*** -Dsonar.branch.name=${branch_name} clean verify sonar:sonar
mvn -Dproject.docker.project=$DOCKER_REPO -Ddocker.allContainers docker:stop -P
integration-test
mvn -Dproject.docker.project=$DOCKER_REPO verify -P integration-test
mvn -Dproject.docker.project=$DOCKER_REPO -DskipUTs=true install docker:push
docker:stop
mvn -X -Dproject.docker.project=$DOCKER_REPO -Dsonar.host.url=*** -Dsonar.login=*** -
Dsonar.password=*** -Dsonar.branch.name=${branch_name} -
Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco-it -
Dsonar.java.binaries=target/classes/com/proofpoint/forensicsstore sonar:sonar
"""
},
tests: {
sh """
mvn install -f tests/pom.xml
"""
buildDocker directory: 'tests', image: "$NAME-tests", arguments: "--build-arg version=$VERSION --build-arg branch=${env.BRANCH_NAME} ."
},
helm: {
packageHelm('*',
'--app-version', env.VERSION,
'--set', "cloud15-helm.k8s-config-hook.service=$NAME",
'--set', "cloud15-helm.k8s-config-hook.serviceVersion=$VERSION",
'--set', "cloud15-helm.k8s-config-hook.oauthClient=false")
}
)
}
stage("Quality Gate"){
steps {
timeout(time: 5, unit: 'MINUTES') {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
waitForQualityGate abortPipeline: true
}
}
}
}
post {
always {
sh """
mvn -Dproject.docker.project=$DOCKER_REPO -Ddocker.allContainers docker:stop -P integration-test
"""
junit '**/target/surefire-reports/*.xml'
step([
$class : 'JacocoPublisher',
execPattern : '**/target/coverage-reports/*.exec',
classPattern : '**/target/classes/com/proofpoint/forensicsstore',
sourcePattern : 'src/main/java',
exclusionPattern : '**/*Test.class'
])
}
}
}
Issue:
Right now my blocker is, sonar qube being able to read the unit tests count and most of the other metrics except code coverage, which is important to me.
Thanks in advance.