I am working in .net core with C# and I written Unit Test cases.
I want to check the code coverage sonarqube with Jenkins pipeline
I generated the code coverage Report using Coverlet
I got the file “coverage.cobertura.xml”
So I need to achieve code coverage Percentage in SonarQube scan while doing build and deploying the application.
For This I need to use script as below
<
dotnet sonarscanner begin /k:"<sonar-project-key>"
/d:sonar.login="<sonar-token>"
/d:sonar.cs.opencover.reportsPaths=coverage.xml
dotnet build --no-incremental
coverlet .\CovExample.Tests\bin\Debug\net6.0\CovExample.Tests.dll
--target "dotnet"
--targetargs "test --no-build"
-f=opencover
-o="coverage.xml"
dotnet sonarscanner end /d:sonar.login="<sonar-token>"
/>
I tried to add script but it seems the format of Jenkins file as shown below is differ from the build script as shown above
Please help me out here how to integrate the code covergare build script to Jenkins file in sonarqube section.
for your referece below is the Jenkins file which i am using now.
stages {
stage('Build') {
agent {
kubernetes {
yaml easyAgents(easyTemplate: 'dotnetcore3')
}
}
stages {
stage('dotnetcore3 Build') {
environment {
CARID = "${CARID}"
LOB = "${LOB}"
}
steps {
container('dotnetcore3') {
dotnetCoreBuild (
credentialsId: "SYSTEM-ID",
nugetPackageSourceUrl: "Url",
generateArtifactoryName: "Artifactory",
restorePath: "./xxxxx/xxxxxx.csproj",
solutionPath: "./xxxxxx/xxxxxx.csproj",
dotnetBuildCommand: "-c Release",
windowsBuild: false
)
// sh "ls -la" // for debugging
}
}
}
stage('docker build') {
steps {
container('docker') {
dockerBuild(
overWrite: true,
name: "${APPLICATION_NAME}",
version: "${DEPLOY_VER}",
namespace: "${ASSIGNEEGROUP_NORMALIZED}"
)
}
}
}
stage('Scans') {
parallel {
stage('Sonar Analysis') {
agent {
kubernetes {
yaml easyAgents(easyTemplate: 'dotnetcore6')
}
}
steps {
container('dotnetcore6') {
sonarScan(
projectKey: 'xxccxcxxcx',
applicationName: "${APPLICATION_NAME}",
projectVersion: "1.0.0",
sonarQualityGate: 'xcxccxc_QualityGate',
sonarLanguage: 'dotnetcore',
dotnetWindowsBuild: false,
sonarExclusions:'**/*.css,**/*.js,wwwroot/lib/**',
msSolutionPath: ['sfsfsfdsfsf.sln']
)
}
}
}
Appreciate your help!!!