简体   繁体   English

使用Jenkins Pipeline为Quality Gate拒绝了sonarqube url连接

[英]sonarqube url connection refused for Quality Gate using Jenkins Pipeline

After a good 2 days trying to get Jenkins pipelines to work I've hit an issue in the Quality Gate section I'm unable to resolve. 经过2天的尝试,让Jenkins管道正常工作后,我在质量门部分遇到了一个我无法解决的问题。

Both Jenkins and SonarQube are on the same server in our network (say 192.168.0.6) Sonarqube can be accessed from this server using localhost:9000 and on my dev computer I've added sonar.ecl to the hosts file pointing to 192.168.0.6 Jenkins和SonarQube都位于我们网络中的同一服务器上(例如192.168.0.6),可以使用localhost:9000从该服务器访问Sonarqube,在我的开发计算机上,我已将sonar.ecl添加到指向192.168.0.6的主机文件中

Jenkins is accessed with 192.168.0.6:8080 on my dev box and localhost:8080 from the netwrok server. 通过我的开发人员箱上的192.168.0.6:8080和netwrok服务器上的localhost:8080访问Jenkins。

Both servers are running and can be visitied from a web browser on my machine and via vnc on the network machine (or from the server itself (it has ubuntu 16.04 on it)) 两台服务器都在运行,并且可以从我的计算机上的Web浏览器或通过网络计算机上的vnc进行访问(或从服务器本身(它具有ubuntu 16.04))进行访问。

I am able to get the project into the workspace and call sonar-scanner to generate the sonarqube analysis which i can see from within sonarqube. 我能够将项目放入工作区并调用声纳扫描仪以生成声纳分析,我可以从声纳中看到该分析。 This is great and works perfectly however the next stage on the pipeline is the call to sonarqube to get the result of the quality gate, this fails with the following java error 这很好并且可以完美运行,但是管道的下一个阶段是调用sonarqube以获取质量门的结果,此操作因以下java错误而失败

java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at com.squareup.okhttp.internal.Platform.connectSocket(Platform.java:101)
    at com.squareup.okhttp.Connection.connectSocket(Connection.java:198)
    at com.squareup.okhttp.Connection.connect(Connection.java:172)
    at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:358)
    at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:117)
    at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
    at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
    at com.squareup.okhttp.Call.getResponse(Call.java:276)
    at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:234)
    at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:196)
    at com.squareup.okhttp.Call.execute(Call.java:79)
    at org.sonarqube.ws.client.HttpConnector.doCall(HttpConnector.java:209)
    at org.sonarqube.ws.client.HttpConnector.get(HttpConnector.java:154)
    at org.sonarqube.ws.client.HttpConnector.call(HttpConnector.java:143)
    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:178)
    at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:127)
    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:122)
    at sun.reflect.GeneratedMethodAccessor455.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 org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:129)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
Caused: java.lang.IllegalStateException: Fail to request http://192.168.0.6:9000/api/ce/task?id=AWSj17JD0O7Ts6ZE1YHG
    at org.sonarqube.ws.client.HttpConnector.doCall(HttpConnector.java:212)
    at org.sonarqube.ws.client.HttpConnector.get(HttpConnector.java:154)
    at org.sonarqube.ws.client.HttpConnector.call(HttpConnector.java:143)
    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:178)
    at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:127)
    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:122)
    at sun.reflect.GeneratedMethodAccessor455.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 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:20)
    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.GeneratedMethodAccessor399.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$101(SandboxContinuable.java:34)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
    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: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)
Finished: FAILURE

Now in Jenkins I've got the url for sonarqube as localhost:9000 and in sonar.properties it is set as sonar.web.host=localhost and sonar.web.port=9000 so I've no idea how it is changing it to 192.168.0.6:9000? 现在在詹金斯,我将sonarqube的URL设置为localhost:9000,在sonar.properties中将其设置为sonar.web.host = localhost和sonar.web.port = 9000,所以我不知道它是如何更改的到192.168.0.6:9000?

Can anyone give me a pointer how to complete this step? 谁能告诉我如何完成此步骤? Here is my pipeline (with credential details not shown) 这是我的管道(未显示凭据详细信息)

node {
   def mvnHome
   stage('SCM') {
      git 'git@bitbucket.org:group/project.git'
      mvnHome = tool 'M3'
   }
   stage('SonarQube analysis') {
        def scannerHome = tool 'SonarQubeScanner';
        withSonarQubeEnv('SonarQube') { 
          sh "${scannerHome}/bin/sonar-scanner " +
          '-Dsonar.projectKey=jobadmin-pipeline:master ' +
          '-Dsonar.login=creds ' +
          '-Dsonar.password=***** ' +
          '-Dsonar.sources=. ' +
          '-Dsonar.exclusions=**/lib/**'
        }
    }
    stage("SonarQube Quality Gate") { 
        timeout(time: 1, unit: 'HOURS') { 
           def qg = waitForQualityGate() 
           if (qg.status != 'OK') {
             error "Pipeline aborted due to quality gate failure: ${qg.status}"
           }
        }
    }
}

Additional Information: On the server hosting jenkins and sonar the following url's work http://localhost:9000 and http://sonar.ecl , but http://192.168.0.6:9000 doesn't. 附加信息:在托管jenkins和声纳的服务器上,以下URL的工作为http:// localhost:9000http://sonar.ecl ,但http://192.168.0.6:9000没有。

My apache conf file is as follows: 我的Apache conf文件如下:

<VirtualHost *:80>
    ServerName sonar.ecl
    ServerAdmin sonar@somewhere.com
    ProxyPreserveHost On
    ProxyPass / http://localhost:9000/
    ProxyPassReverse / http://localhost:9000/
    TransferLog /var/log/apache2/sonar_access.log
    ErrorLog /var/log/apache2/sonar_error.log
</VirtualHost>

I still haven't determined why java is looking at http://192.168.0.6:9000 is there another location I've overlooked, even grep for 192.168.0.6 hasn't helped yet. 我仍然不确定为什么Java正在查看http://192.168.0.6:9000 ,还有另一个我忽略的位置,甚至192.168.0.6的grep都没有帮助。

In jenkins the url seems to change as the scanner is finishing 在詹金斯语中,URL似乎随着扫描仪完成而改变

13:03:54.840 DEBUG: POST 200 http://localhost:9000/api/ce/submit?projectKey=jobadmin-pipeline:master | time=244ms
13:03:54.842 INFO: Analysis report uploaded in 246ms
13:03:54.842 INFO: ANALYSIS SUCCESSFUL, you can browse http://192.168.0.6:9000/dashboard/index/jobadmin-pipeline:master
13:03:54.842 INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
13:03:54.842 INFO: More about the report processing at http://192.168.0.6:9000/api/ce/task?id=AWSoIB5vjatNRUhjlocT

I've since reconfigured the url in jenkins to use sonar.ecl but again it hits the end of the Analysis and shows the same incorrect url ( http://192.168.0.6:9000/dashboard/index/jobadmin-pipeline:master - ie not sonar.ecl) and this is used in quality gate and breaks. 此后,我已经在jenkins中将网址重新配置为使用sonar.ecl,但它再次出现在分析末尾并显示了相同的错误网址( http://192.168.0.6:9000/dashboard/index/jobadmin-pipeline:master-即不是sonar.ecl),它用于质量门和中断。

So as i see it there are 2 solutions 1/ we find where this ip address is coming from or 2 we allow this ip in apache. 因此,如我所见,有2个解决方案1 ​​/我们找到了该IP地址的来源或2我们允许在apache中使用此IP。

I'm not sure how to do either, I tried the latter for at least 6 hours yesterday and was unable to have the url of 192.168.0.6:9000 to work on SonarQube yet sonar.ecl works (via hosts on the server) 我不确定该怎么办,昨天我尝试了至少6个小时,但无法在SonarQube上使用192.168.0.6:9000的网址,但sonar.ecl可以工作(通过服务器上的主机)

Thanks in advance 提前致谢

As G. Ann had suggested this was down to an incorrect url setting in SonarQube (Administration > General > Server base URL) setting this to http://localhost:9000 fixed my issue completely. 正如G. Ann所建议的那样,这归因于SonarQube中的url设置不正确(管理>常规>服务器基本URL),将其设置为http:// localhost:9000可以完全解决我的问题。 Huge upvote for having this one from the start. 从一开始就拥有此功能的巨大赞誉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM