错误:无法访问声纳服务器'http:// localhost:9000'

Guy*_*ton 17 build sonarqube

运行以下命令时:cmd/c C:\ sonar-runner-2.4\bin\sonar-runner.bat

(声纳运行器安装在构建机器上)我收到以下错误:
错误:无法访问声纳服务器' http:// localhost:9000 '
错误:声纳运行程序执行期间
出错ERROR:java.net.ConnectException:连接被拒绝:connect
ERROR:引起:连接被拒绝:连接

什么可能导致这些错误?

嗨dinesh,

这是我的sonar-runner.properties文件:

sonar.projectKey=NDM
sonar.projectName=NDM
sonar.projectVersion=1.0

sonar.visualstudio.solution=NDM.sln

#sonar.sourceEncoding=UTF-8
sonar.web.host:sonarqube
sonar.web.port=9000

# Enable the Visual Studio bootstrapper
sonar.visualstudio.enable=true

# Unit Test Results
sonar.cs.vstest.reportsPaths=TestResults/*.trx

# Required only when using SonarQube < 4.2
sonar.language=cs

sonar.sources=.
Run Code Online (Sandbox Code Playgroud)

你可以看到我设置了sonar.web.host:sonarqube sonar.web.port = 9000但是当我运行sonar-runner.bat时我仍然得到
错误:声纳服务器' http:// localhost:9000 '不能到达 - 为什么它还在寻找localhost:9000
而不是sonarqube:我设置了9000?

我在sonar-runner.bat的日志中看到了以下行:INFO:工作目录:D:\ sTFS\26091\Sources\NDM\Source..sonar

而我的解决方案是在D:\ sTFS\26091\Sources\NDM\Source \

这可能是问题吗?

谢了,兄弟们

roi*_*ere 28

如果将SonarScanner CLI与 Docker 一起使用,则可能会出现此错误,因为 SonarScanner 容器无法访问 Sonar UI 容器。

请注意,使用来自另一个容器的简单卷曲,您将遇到相同的错误:

docker run --rm byrnedo/alpine-curl 127.0.0.1:9000
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused
Run Code Online (Sandbox Code Playgroud)

解决方案是将 SonarScanner 容器连接到声纳实例的同一个 docker网络,例如--network=host

docker run --network=host -e SONAR_HOST_URL='http://127.0.0.1:9000' --user="$(id -u):$(id -g)" -v "$PWD:/usr/src" sonarsource/sonar-scanner-cli
Run Code Online (Sandbox Code Playgroud)

(此命令的其他参数来自SonarScanner CLI 文档


小智 8

我遇到了同样的问题,我改成 IP 并且运行良好

转至系统参考 --> 网络 --> 高级 --> 打开 TCP/IP 选项卡 --> 复制 IPv4 地址。

更改该 IP 而不是 localhost

希望这可以帮助


Din*_*eyn 6

您应该将声纳运行器配置为使用现有的SonarQube服务器。为此,您需要更新其conf/sonar-runner.properties文件并指定SonarQube服务器URL,用户名,密码和JDBC URL。有关详细信息,请参见https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

如果尚未启动并运行SonarQube服务器,则可以在本地启动一个(使用默认配置)-它会绑定到http:// localhost:9000并使用默认的声纳运行器配置。有关如何开始使用SonarQube服务器的详细信息,请参阅https://docs.sonarqube.org/latest/setup/get-started-2-minutes/


Ada*_*ise 5

对于在不使用 sonar-runners.property 文件的项目中遇到此问题的其他人,您可能会发现(就像我一样)需要调整 pom.xml 文件,添加 sonar.host.url 属性。

例如,我需要在“properties”元素下添加以下行:

<sonar.host.url>https://sonar.my-internal-company-domain.net</sonar.host.url>
Run Code Online (Sandbox Code Playgroud)

其中 url 指向我们的内部声纳部署。