詹金斯 - sonarQube 问题 ||声纳扫描仪插件

Posted

技术标签:

【中文标题】詹金斯 - sonarQube 问题 ||声纳扫描仪插件【英文标题】:Jenkins - sonarQube Issue || sonarScanner Plugin 【发布时间】:2020-01-10 12:53:31 【问题描述】:

我们使用 Maven 自动安装默认扫描器将 Jenkins 与 sonarQube 服务器集成。声纳扫描仪工作正常,通过 sonarQube 服务器发布结果,但在 waitForQualityGate() 处,出现以下错误。

Sonar Scanner Plugin - 2.9
Jenkins Version - 2.189
sonarQube Server - 7.2 (Community Edition)



验证声纳结果时出错:

[Pipeline]  (SonarQube Quality Gate Results)
[Pipeline] timeout
Timeout set to expire in 1 hr 0 min
[Pipeline] 
[Pipeline] waitForQualityGate
Checking status of SonarQube task 'XYZ-123456789' on server 'my_SQ_server'
[Pipeline] 
[Pipeline] // timeout
[Pipeline] 
[Pipeline] // stage
[Pipeline] 
[Pipeline] 
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.IOException: Failed to authenticate with proxy
    at okhttp3.internal.connection.RealConnection.createTunnel(RealConnection.java:349)
    at okhttp3.internal.connection.RealConnection.connectTunnel(RealConnection.java:197)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:145)
    at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:192)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121)
    at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
    at okhttp3.RealCall.execute(RealCall.java:69)
    at org.sonarqube.ws.client.HttpConnector.doCall(HttpConnector.java:188)
    at org.sonarqube.ws.client.HttpConnector.get(HttpConnector.java:124)
    at org.sonarqube.ws.client.HttpConnector.call(HttpConnector.java:111)
    at hudson.plugins.sonar.client.HttpClient.getHttp(HttpClient.java:37)
    at hudson.plugins.sonar.client.WsClient.getCETask(WsClient.java:51)
    at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.checkTaskCompleted(WaitForQualityGateStep.java:215)
    at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:159)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:286)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
    at sun.reflect.GeneratedMethodAccessor1726.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:160)
    at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
    at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:158)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:162)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:132)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:132)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:132)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
Caused: java.lang.IllegalStateException: Fail to request https://FQDN/api/ce/task?id=XXXXX
    at org.sonarqube.ws.client.HttpConnector.doCall(HttpConnector.java:190)
    at org.sonarqube.ws.client.HttpConnector.get(HttpConnector.java:124)
    at org.sonarqube.ws.client.HttpConnector.call(HttpConnector.java:111)
    at hudson.plugins.sonar.client.HttpClient.getHttp(HttpClient.java:37)
    at hudson.plugins.sonar.client.WsClient.getCETask(WsClient.java:51)
    at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.checkTaskCompleted(WaitForQualityGateStep.java:215)
    at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:159)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:286)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
    at sun.reflect.GeneratedMethodAccessor1726.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:160)
    at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
    at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:158)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:162)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:132)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:132)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:132)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
    at WorkflowScript.run(WorkflowScript:36)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:84)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:78)
    at sun.reflect.GeneratedMethodAccessor647.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:129)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    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:186)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:370)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:93)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:282)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:270)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:66)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
    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)

验证码:

stage("SonarQube Quality Gate Results")
            timeout(time: 1, unit: 'HOURS')  // Just in case something goes wrong, pipeline will be killed after a timeout
            def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
            if (qg.status != 'OK') 
                error "Pipeline Aborted due to Quality Gate failure: $qg.status"
            
            print "Pipeline Quality Gate Status: $qg.status, proceeding with BUILD & Deploy Procedures..."   
        
    

感谢您对此的帮助。

这是我们已经尝试过的...假设错误是由于某些代理配置引起的,可能是声纳扫描仪使用了与系统不同的代理。已经在下面尝试过:

    在我的 VCS 的 sonar-project.properties 中 http.nonProxyHosts=sonarServerFQDN(没用) https.nonProxyHosts=sonarServerFQDN(不起作用) sonar.ce.javaAdditionalOpts="-Dhttp.nonProxyHosts=sonarServerFQDN"(没用)

    将环境变量声明为

SONAR_SCANNER_OPTS -Dhttp.nonProxyHosts=sonarServerFQDN

(没用)

需要注意的是,Webhook 在 Sonar 服务器控制台中正确反映了 Last Delivery。

非常感谢您帮助解决这个问题。

【问题讨论】:

【参考方案1】:
Caused: java.lang.IllegalStateException: Fail to request https://FQDN/api/ce/task?id=XXXXX

这意味着你还没有定义 sonarqube 服务器。

sonarServerFQDN 参数应替换为您的 sonarqube 服务器 url,例如: https.nonProxyHosts=sonar.yourcompany.com

【讨论】:

您好 Fauzan,感谢您的回复,但我已经定义了它...通过 SONAR_SCANNER_OPTS Jenkins 环境变量... -Dhttp.nonProxyHosts=sonarServerFQDN.company.com 但仍然是同样的问题 您是否尝试过像 Dhttp.nonProxyHosts=yoursonarserver.com 一样直接定义它? 直接在哪里定义呢? 仍然卡在这个...所以詹金斯成功提交作业,但在使用 waitForQualityGate() 请求结果时失败...所以不知何故 waitForQualityGate() 正在使用特定代理...不知道如何解决这个问题。 不要忘记为身份验证添加用户和密码参数。 sonar.jdbc.username= sonar.jdbc.password=

以上是关于詹金斯 - sonarQube 问题 ||声纳扫描仪插件的主要内容,如果未能解决你的问题,请参考以下文章

如何从詹金斯管道中选择声纳质量门?

Sonarqube 与声纳扫描仪

SonarQube 没有获得单元测试覆盖率

使用单体项目的 Spotbugs 规则运行声纳扫描仪时出错?

如何在 Jenkins 声明式管道中设置声纳扫描仪

在 gitlab-ci 中运行声纳扫描仪