java - Sonarqube 与 Gitlab CI 集成 - 无法访问 SonarQube 服务器
问题描述
我一直在寻找这个问题的答案,但我找不到适合我的解决方案。
我正在尝试将 sonarqube 与 Gitlab CI 一起使用。我对这件事真的很陌生。
到目前为止,我可以安装 sonarqube 的 docker 映像并在本地成功运行它。但是,当我尝试使其与 gitlab CI 一起工作时,我得到“无法访问 SonarQube 服务器 [192.168.10.5:9000]”。192.168.10.5 是我的 IP,9000 是我正在使用的端口。
我在一个 java 8 - maven 项目中工作。
这是我在 pom.xml 中用于 sonarqube 的插件:
...
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.0.905</version>
</plugin>
...
在我的 .m2/settings.xml 我有这个配置文件:
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>http://192.168.10.5:9000</sonar.host.url>
</properties>
</profile>
这是我的 gitlab-ci.yml:
image: maven:3.6.3-jdk-8
variables:
SONAR_TOKEN: "myUserToken"
SONAR_HOST_URL: "192.168.10.5:9000"
GIT_DEPTH: 0
cache:
paths:
- .m2/repository
stages:
- quality_test
- build
quality_test:
stage: quality_test
script:
- mvn pmd:check
- mvn verify sonar:sonar -Dsonar.qualitygate.wait=true -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_TOKEN -DskipTests
allow_failure: true
build:
stage: build
script:
- mvn package -DskipTests
artifacts:
paths:
- target/com.jar
当我推送到 gitlab 时,管道“通过”并带有“警告”:
[INFO] User cache: /root/.sonar/cache
[ERROR] SonarQube server [192.168.10.5:9000] can not be reached
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.785 s
[INFO] Finished at: 2020-06-16T20:16:23Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar (default-cli) on project project: Unable to execute SonarQube: Fail to get bootstrap index from server: unexpected url: 192.168.10.5:9000/batch/index -> [Help 1]
我知道它无法访问我用“192.168.10.5:9000”指定的服务器,其中 192.168.10.5 是我的 IP。我尝试使用 localhost:9000 得到相同的结果。
gitlab ci 运行器未在本地执行。
我真的坚持这一点。任何帮助将非常感激。
提前道歉,这是我的第一篇文章,英语不是我的母语。
解决方案
推荐阅读
- bitbucket - 使用 Java 监控 BitBucket 中的代码提交
- php - 将 PHP-FPM 限制为一次执行一次
- r - 在数据框的每个原始行旁边添加新行,并且每个新行添加指定列的相同值
- sql - 虽然循环 SQL 没有填充完整的结果
- python - 当我销毁我的 tkinter 根时,会弹出一个灰色窗口,我必须关闭它,我该如何修复它
- excel - VBA比较两个列表并删除不同列中具有重复值的行
- google-apps-script - GOOGLE FORM - 如何在代码中指定子文件夹名称?
- vaadin - Vaadin 8 - 警告:不推荐添加 Object 类型的侦听器,事件侦听器应扩展 SerializableEventListener
- php - 如何通过 php 客户端发送 websocket 升级标头
- c - 我编写了一个代码,它查找数组的最小和最大元素并将其反转元素。但是在我构建它之后它给了我一个输出错误