运行以下命令时: cmd/c C:\sonar-runner-2.4\bin\sonar-runner.bat
( Sonar 运行器安装在构建机器上)
我收到以下错误:
错误: Sonar 服务器'http://localhost:9000 ' 无法到达
错误:Sonar runner 执行期间出错
错误:java.net.ConnectException:连接被拒绝:连接
错误:原因:连接被拒绝:连接
什么会导致这些错误?
你好,
这是我的 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=.
如您所见,我设置了 sonar.web.host:sonarqube
sonar.web.port=9000 但是当我运行 sonar-runner.bat 我仍然得到
错误: Sonar 服务器'http://localhost:9000 ' 无法访问 - 为什么它仍在寻找 localhost:9000
而不是我设置的 sonarqube:9000?
我在 sonar-runner.bat 的日志中看到了以下行: INFO:工作目录:D:\sTFS\26091\Sources\NDM\Source..sonar
虽然我的解决方案位于 D:\sTFS\26091\Sources\NDM\Source\
这可能是问题吗?
谢谢, 伙计
最佳答案
如果您使用 SonarScanner CLI使用 Docker,您可能会遇到此错误,因为 SonarScanner 容器无法访问 Sonar UI 容器。
请注意,使用来自另一个容器的简单 curl 也会遇到相同的错误:
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
解决方法是将 SonarScanner 容器连接到同一个 docker network您的 Sonar 实例,例如使用 --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
(该命令其他参数来源于SonarScanner CLI documentation)
关于build - 错误 : Sonar server 'http://localhost:9000' can not be reached,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32097414/