Jenkins Plugin: MSBuild Scanner: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.

2,049 views
Skip to first unread message

mitchel...@live.com

unread,
Feb 10, 2018, 5:23:53 PM2/10/18
to SonarQube
Hello,

We currently have both MSBuild and Java scanners running and I am getting the error "Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis." when running the MS Build scanner in a Jenkins Pipeline Script but it works with the Java (regular) scanner for a different job (different code).

The pipeline scripts and Jenkins instance are the same so I am thinking this is an issue with the MS Build Scanner not setting the CE ID for the current Jenkins job run.

Before I start to look into using the REST API using the CE ID set in the .sonarqube\out\.sonar\report-task.txt I was hoping I could get some help or help with a bug.

I checked the SonarQube server and it has the analysis so that is working correctly.

Jenkins Version: 2.89.3
SonarQube Scanner For Jenkins Plugin Version: 2.6.1
MS Build Scanner Version: 4.0.2.892
SonarQube Server Versio: 7.0.0.36138


Pipeline Script:

stage('SonarQube-Start') {
    when { branch 'develop' }
    steps {
        withSonarQubeEnv('SonarQube') {
            withCredentials([string(credentialsId: 'sonar-duke-token', variable: 'SONAR_TOKEN')]) {
                powershell """
                    ${env.MSBUILD_SONAR_HOME}\\SonarQube.Scanner.MSBuild.exe begin `
                    /k:${env.SONAR_PROJECT_KEY} `
                    /v:${env.VERSION_NUMBER} `
                    /d:sonar.login=${env.SONAR_TOKEN} `
                    /d:sonar.log.level=DEBUG
                """
            }
        }
    }
}

// MS Build Stage (omitted)

stage('SonarQube-Publish') {
    when { branch 'develop' }
    steps {
        withSonarQubeEnv('SonarQube') {
            powershell "${env.MSBUILD_SONAR_HOME}\\SonarQube.Scanner.MSBuild.exe end"
        }
    }
}


// Removed Script with if statement for checking status just for testing.
stage('SonarQube-QualityGate') {
    when { branch 'develop' }
    steps {
        withSonarQubeEnv('SonarQube') { waitForQualityGate() }
    }
}


ERROR:

java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.
	at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.processStepParameters(WaitForQualityGateStep.java:125)
	at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:107)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:229)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)
	at sun.reflect.GeneratedMethodAccessor604.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:133)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:159)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:129)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:129)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
	at WorkflowScript.run(WorkflowScript:157)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:77)
	at sun.reflect.GeneratedMethodAccessor468.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	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:174)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:331)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:82)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:243)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:231)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)



G. Ann Campbell

unread,
Feb 12, 2018, 11:59:48 AM2/12/18
to SonarQube
Hi,

You're passing credentials in to your begin step but not your end step. This is likely the source of the error (with, yes, a slightly misleading error message in this case).


Ann

mitchel...@live.com

unread,
Feb 12, 2018, 12:59:02 PM2/12/18
to SonarQube
Hey Ann,

That seemed to do it. Now the step is going into it's paused state waiting for the CE Task to finish.

The issue now is it seemed to get stuck in the pause. I checked the SonarQube Server and the CE Task is completed and the Quality Gate got an OK status. I do have the webhooks setup and it is working for a Java project on the same Jenkins server.

Pipeline Script:

stage('SonarQube-Start') {
    when { branch 'develop' }
    steps {
        withSonarQubeEnv('SonarQube') {
            withCredentials([string(
credentialsId: 'sonar-duke-token', variable: 'SONAR_TOKEN')]) {
                powershell """
                    ${env.MSBUILD_SONAR_HOME}\\SonarQube.Scanner.MSBuild.exe begin `
                    /k:${env.SONAR_PROJECT_KEY} `
                    /v:${env.VERSION_NUMBER} `
                    /d:sonar.login=${env.SONAR_TOKEN} `
                    /d:sonar.log.level=DEBUG
                """
            }
        }
    }
}

// MS Build Stage (omitted)

stage('SonarQube-Publish') {
    //when { branch 'develop' }

    steps {
        withSonarQubeEnv('SonarQube') {
            withCredentials([string(credentialsId: 'sonar-duke-token', variable: 'SONAR_TOKEN')]) {
                powershell """
                    ${env.MSBUILD_SONAR_HOME}\\SonarQube.Scanner.MSBuild.exe end `
                        /d:sonar.login=${env.SONAR_TOKEN}
                """
            }
        }
    }
}


// Removed Script with if statement for checking status just for testing.
stage('SonarQube-QualityGate') {
    when { branch 'develop' }
    steps {
        withSonarQubeEnv('SonarQube') { waitForQualityGate() }
    }
}

Build Log:
11:52:30 Timeout set to expire in 1 hr 0 min
[Pipeline] {
[Pipeline] withSonarQubeEnv
11:52:30 Injecting SonarQube environment variables using the configuration: SonarQube
[Pipeline] {
[Pipeline] waitForQualityGate
11:52:30 Checking status of SonarQube task 'AWGLJYeSdrvNYNFQ_o53' on server 'SonarQube'
11:52:30 SonarQube task 'AWGLJYeSdrvNYNFQ_o53' status is 'IN_PROGRESS'''

SonarQube Status:
task
id"AWGLJYeSdrvNYNFQ_o53"
type"REPORT"
componentId"AWGGH7GIdrvNYNFQ_o44"
componentKey"duke-web-test"
componentName"duke-web-test"
componentQualifier"TRK"
analysisId"AWGLJY0siTnWtaGl35OX"
status"SUCCESS"
submittedAt"2018-02-12T11:52:28-0600"
submitterLogin"MM025313"
startedAt"2018-02-12T11:52:29-0600"
executedAt"2018-02-12T11:52:33-0600"
executionTimeMs3718
logsfalse
hasScannerContexttrue
organization"default-organization"

G. Ann Campbell

unread,
Feb 12, 2018, 1:36:10 PM2/12/18
to SonarQube
Hi,

You should double-check the Jenkins log for evidence of the webhook call.


Ann

mitchel...@live.com

unread,
Feb 12, 2018, 2:08:16 PM2/12/18
to SonarQube
Hey Ann,

I have looked in the Jenkins logs but did not find anything logged for a SonarQube web-hook. I also ran our Java build which is working with the wait for quality gate check and still nothing in the logs.

If there a specific place or log I need to enable?

Thanks,
Mitchell Maler

G. Ann Campbell

unread,
Feb 12, 2018, 2:12:00 PM2/12/18
to mitchel...@live.com, SonarQube
Hi Mitchell,

Just to make sure, I'm talking about the Jenkins server log, not the job log.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/1CEukZ7uJnE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/2d307459-6da5-4fff-8432-ff7bba96cbc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mitchel...@live.com

unread,
Feb 12, 2018, 2:17:36 PM2/12/18
to SonarQube
Hey Ann,

That is what I assumed. I went to the server logs on the actual server and also looked at the All Jenkins Logs in the UI.

Thanks,
Mitchell Maler

G. Ann Campbell

unread,
Feb 12, 2018, 2:24:42 PM2/12/18
to mitchel...@live.com, SonarQube
Hi Mitchell,

I asked because in other threads it has been mentioned that Jenkins should log something when it receives the webhook payload. In the past this lack of logging has pointed to incorrect webhook configuration. 


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/1CEukZ7uJnE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.

mitchel...@live.com

unread,
Feb 12, 2018, 5:13:31 PM2/12/18
to SonarQube
Hey Ann,

Thanks for pointing me in the right direction. It seems the Webhook was failing which is why it would get stuck. I turned up the logging to TRACE on the sonar server which showed me the TCP error.
I am guessing the Sonar Wait pulls for the status first before going into a paused status which is why it was working for our Java project since it isn't that large and finished before it was even called.

Thanks,
Mitchell Maler

mitchel...@live.com

unread,
Feb 12, 2018, 5:22:55 PM2/12/18
to SonarQube
After switching to HTTP that seemed to fix the issue.

Is there documentation on how to add our Certs to the SonarQube server so we can use HTTPS? I am going to guess it is just using the default java key store that is part of the JVM but wanted to make sure.

G. Ann Campbell

unread,
Feb 13, 2018, 7:17:27 AM2/13/18
to mitchel...@live.com, SonarQube
Hi Mitchell,

I'm glad you worked through this. And I think you're right about why it was working for the Java project. There is an immediate status check. 

For https, the assumption is that you'll put a proxy in front of your instance.


HTH,
Ann


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

On Mon, Feb 12, 2018 at 5:22 PM, <mitchel...@live.com> wrote:
After switching to HTTP that seemed to fix the issue.

Is there documentation on how to add our Certs to the SonarQube server so we can use HTTPS? I am going to guess it is just using the default java key store that is part of the JVM but wanted to make sure.

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/1CEukZ7uJnE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.

Amaury Leve

unread,
Feb 14, 2018, 4:32:20 AM2/14/18
to G. Ann Campbell, mitchel...@live.com, SonarQube
Hi,

I am not sure if we can do any improvement for the certificate but we can certainly improve the failure when credentials are not passed in the end step but were specified during the begin step (here is the ticket to track the issue: https://jira.sonarsource.com/browse/SONARMSBRU-378).

Cheers,
Amaury

On Tue, Feb 13, 2018 at 1:17 PM G. Ann Campbell <ann.ca...@sonarsource.com> wrote:
Hi Mitchell,

I'm glad you worked through this. And I think you're right about why it was working for the Java project. There is an immediate status check. 

For https, the assumption is that you'll put a proxy in front of your instance.


HTH,
Ann


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

On Mon, Feb 12, 2018 at 5:22 PM, <mitchel...@live.com> wrote:
After switching to HTTP that seemed to fix the issue.

Is there documentation on how to add our Certs to the SonarQube server so we can use HTTPS? I am going to guess it is just using the default java key store that is part of the JVM but wanted to make sure.

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/1CEukZ7uJnE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/CAEi9rUJHUZUZpOk_Yr%3D3EShDNkmdw4gxtMEQYQi8yLom-K8f9Q%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.
--

Amaury Levé | SonarSource

Software Developer - .Net Team

http://sonarsource.com


Are you using SonarLint in your IDE? 

mitchel...@live.com

unread,
Feb 14, 2018, 9:51:22 PM2/14/18
to SonarQube
 Hey Amaury,

Thanks for created the JIRA. That should help others that have the same issues.

I am now trying to figure out how to get SonarQube to accept an internal SSL Certificate. The server itself is behind a reverse proxy and same with Jenkins but the SSL Cert is an internal one. When SonarQube tries to send a Webhook call to the Jenkins sever I get a TCP SSL cert error since it cannot trust it.
Since that cert is internal I feel like I need to import it to SonarQube so it can trust it when sending the webhook. Do you have any steps or documentation on how to do so?

Thanks,
Mitchell Maler

Julien HENRY

unread,
Feb 15, 2018, 8:13:29 AM2/15/18
to SonarQube
Hi,

For SSL, it should be a matter of adding your custom certificate to the truststore of the JVM running the SonarQube server.

++

Julien
Reply all
Reply to author
Forward
0 new messages