Must-share information (formatted with Markdown):
-
which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
SonarQube 9.9 Developer Edition
SonarScanner for MSBuild 5.5.3
SonarQube Scanner Plugin for Jenkins v 2.15 -
what are you trying to achieve
Scan project and Implement Quality gate to fail pipeline on Failure
Web hook has been setup at sonarqube and seems to be receiving data after each scan
- what have you tried so far to achieve this
Tried to troubleshoot and increase sonar debug level to see errors:
Part of the jenkins groovy file in question:
stage ('Build solution') {
steps {
dir('BlueSky') {
withCredentials([string(credentialsId: 'xxx', variable: 'TOKEN')]) {
withSonarQubeEnv('sonar') {
bat """
"${tool 'sonar'}\\SonarScanner.MSBuild.exe" begin /k:NRSBSS_phoenix /d:sonar.login=${TOKEN} /d:sonar.cs.opencover.reportsPaths=opencover.coverageresults.xml /d:sonar.verbose=true /d:sonar.pullrequest.key=${PR} /d:sonar.pullrequest.branch=${PR} /d:sonar.pullrequest.base=master /d:sonar.log.level=DEBUG || exit
${tool 'nuget'} restore BlueSky.sln || exit
"${tool 'MSBUILD15'}" BlueSky.sln /t:Build /p:Configuration=Debug /p:DebugType=pdbonly /p:ExcludeGeneratedDebugSymbol=false /p:DeployOnBuild=true /p:DeployTarget=Package || exit
"""
}
}
}
}
}
stage('Complete SonarQube Scan') {
steps {
dir('BlueSky') {
withCredentials([string(credentialsId: 'xxx', variable: 'TOKEN')]) {
bat """
"${tool 'sonar'}\\SonarScanner.MSBuild.exe" end /d:sonar.login=${TOKEN} || exit
"""
}
}
}
}
stage("Quality Gate") {
steps {
dir('BlueSky') {
withCredentials([string(credentialsId: 'xxx', variable: 'TOKEN')]) {
script{
dir('BlueSky') {
timeout(time: 1, unit: 'HOURS') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
}
}
}
}
Warning from Scanner log:
I see the Scanner “begin” complete successfully and then I see this warning:
[Pipeline] }
[2023-03-22T23:58:16.018Z] WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeed?
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Complete SonarQube Scan)
[Pipeline] dir
But later I see the file being written to a location by the “end” of the sonar scanner
[2023-03-23T00:05:39.438Z] 00:05:39.139 DEBUG: Report metadata written to D:\Jenkins\workspace\BlueSky SonarQube PR Testing\BlueSky\.sonarqube\out\.sonar\report-task.txt
[2023-03-23T00:05:39.438Z] 00:05:39.139 INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://jenkins.dev.xxx.com/sonarqube/dashboard?id=NRSBSS_phoenix&pullRequest=1253
[2023-03-23T00:05:39.438Z] 00:05:39.139 INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[2023-03-23T00:05:39.438Z] 00:05:39.139 INFO: More about the report processing at https://jenkins.dev.xxx.com/sonarqube/api/ce/task?id=AYcLyRBx-G0QqU2ZyDqz
[2023-03-23T00:05:39.438Z] 00:05:39.142 DEBUG: Post-jobs :
[2023-03-23T00:05:39.438Z] 00:05:39.148 DEBUG: eslint-bridge server will shutdown
[2023-03-23T00:05:44.688Z] 00:05:44.149 DEBUG: eslint-bridge server closed
[2023-03-23T00:05:44.688Z] 00:05:44.150 INFO: Time spent writing ucfgs 0ms
[2023-03-23T00:05:49.948Z] 00:05:49.850 INFO: Analysis total time: 7:29.317 s
[2023-03-23T00:05:49.948Z] 00:05:49.854 INFO: ------------------------------------------------------------------------
[2023-03-23T00:05:49.948Z] 00:05:49.854 INFO: EXECUTION SUCCESS
[2023-03-23T00:05:49.948Z] 00:05:49.854 INFO: ------------------------------------------------------------------------
[2023-03-23T00:05:49.948Z] 00:05:49.854 INFO: Total time: 7:31.369s
[2023-03-23T00:05:50.205Z] 00:05:50.004 INFO: Final Memory: 86M/308M
[2023-03-23T00:05:50.205Z] 00:05:50.004 INFO: ------------------------------------------------------------------------
[2023-03-23T00:05:50.462Z] Process returned exit code 0
[2023-03-23T00:05:50.462Z] The SonarScanner CLI has finished
[2023-03-23T00:05:50.462Z] 00:05:50.306 Post-processing succeeded.
Error while executing quality gate stage:
[Pipeline] waitForQualityGate
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] bat
[2023-03-23T00:05:52.260Z]
[2023-03-23T00:05:52.260Z] D:\Jenkins\workspace\BlueSky SonarQube PR Testing>echo {"id": "1253", "state": "failure", "description": "Build job failed", "target_url": "https://jenkins.dev.xxx.com/job/BlueSky%20SonarQube%20PR%20Testing/62/"} 1>status.json
[2023-03-23T00:05:52.260Z]
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.IllegalStateException: Unable to guess SonarQube task id and/or SQ server details. Please use the 'withSonarQubeEnv' wrapper to run your analysis.
at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.processStepParameters(WaitForQualityGateStep.java:215)
at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:174)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:322)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:196)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:124)
at jdk.internal.reflect.GeneratedMethodAccessor2848.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:180)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:163)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:178)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:182)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:152)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at WorkflowScript.run(WorkflowScript:101)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:90)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:116)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:80)
at jdk.internal.reflect.GeneratedMethodAccessor423.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:152)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:146)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:146)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:420)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Finished: FAILURE