本文介绍了使用Jenkins Pipeline为Quality Gate拒绝了sonarqube url连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

经过2天的尝试,让Jenkins管道正常工作后,我在质量门"部分遇到了一个我无法解决的问题.

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.

Jenkins和SonarQube都位于我们网络中的同一服务器上(例如192.168.0.6),可以使用localhost:9000从该服务器访问Sonarqube,在我的开发计算机上,我已将sonar.ecl添加到指向以下文件的hosts文件中192.168.0.6

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是通过我的开发箱上的192.168.0.6:8080和来自netwrok服务器的localhost:8080进行访问的.

Jenkins is accessed with 192.168.0.6:8080 on my dev box and localhost:8080 from the netwrok server.

这两个服务器都在运行,并且可以通过我的计算机上的Web浏览器或通过网络计算机上的vnc进行访问(或从服务器本身(它具有ubuntu 16.04))进行访问

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))

我能够将项目放入工作区并调用声纳扫描仪以生成声纳分析,我可以从声纳中看到该分析.这很棒,并且效果很好,但是管道的下一个阶段是调用sonarqube以获取质量门的结果,此操作因以下Java错误而失败

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

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

现在在Jenkins中,我将sonarqube的URL设置为localhost:9000,在sonar.properties中将其设置为sonar.web.host = localhost和sonar.web.port = 9000,所以我不知道它如何要将其更改为192.168.0.6:9000?

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?

任何人都可以给我指点一下如何完成此步骤吗?这是我的管道(未显示凭据详细信息)

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 '[email protected]: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}"
           }
        }
    }
}

其他信息:在托管jenkins和声纳的服务器上,以下URL的工作 http://localhost:9000 http://sonar.ecl ,但 http: //192.168.0.6:9000 不会.

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.

我的apache conf文件如下:

My apache conf file is as follows:

<VirtualHost *:80>
    ServerName sonar.ecl
    ServerAdmin [email protected]
    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>

我仍然不确定Java为什么要查看 http://192.168.0.6:9000 是还有一个我忽略的位置,甚至192.168.0.6的grep都没有帮助.

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.

在詹金斯大学,URL似乎随着扫描仪的完成而改变

In jenkins the url seems to change as the scanner is finishing

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

此后,我在jenkins中重新配置了URL以使用sonar.ecl,但它再次出现在Analysis的末尾,并显示了相同的错误URL( http://192.168.0.6:9000/dashboard/index/jobadmin-pipeline:master -即不是sonar.ecl),它用于质量门和休息.

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.

因此,我看到有2个解决方案1 ​​/我们找到了该IP地址的来源或2我们允许在apache中使用此IP.

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.

我不确定该怎么做,昨天我尝试了至少6个小时,但无法使192.168.0.6:9000的URL在SonarQube上工作,但sonar.ecl可以工作(通过主机服务器)

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)

预先感谢

推荐答案

正如G. Ann所建议的,这归因于SonarQube(管理>常规>服务器基本URL)中的不正确的url设置,将其设置为 http://localhost:9000 完全解决了我的问题.从一开始就拥有这个,这是巨大的赞誉.

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. Huge upvote for having this one from the start.

这篇关于使用Jenkins Pipeline为Quality Gate拒绝了sonarqube url连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 20:55