【问题标题】:SonarQube Unable to reach LocalhostSonarQube 无法访问本地主机
【发布时间】:2020-12-09 18:35:21
【问题描述】:

我正在尝试通过 jenkins 管道脚本构建 sonarqube,在构建过程中出现错误,无法到达 localhost 9000。

15:30:58.225 ERROR: SonarQube server [http://localhost:9000] can not be reached
15:30:58.225 INFO: ------------------------------------------------------------------------
15:30:58.226 INFO: EXECUTION FAILURE
15:30:58.226 INFO: ------------------------------------------------------------------------
15:30:58.227 INFO: Total time: 0.603s
15:30:58.243 INFO: Final Memory: 3M/121M
15:30:58.245 INFO: ------------------------------------------------------------------------
15:30:58.246 ERROR: Error during SonarQube Scanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube
    at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
    at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
    at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
    at org.sonarsource.scanner.cli.Main.execute(Main.java:73)
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
    at 
Caused by: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9000

注意:我可以在 y 浏览器中访问我的 localhost sonar 9000,并且在上面的 jenkins 输出中,有一个构建点 url,例如 localhost:9000 也可以从 jenkins 日志中访问,但在行尾是无法到达主机 127.0.0.1 之类的一行

vi /etc/hosts
127.0.0.1 sonarqube
def label = "worker-${UUID.randomUUID().toString()}"

podTemplate(label: label, containers: [
        containerTemplate(name: 'nodejs', image: 'node:10-buster', ttyEnabled: true, command: 'cat'),
            containerTemplate(name: 'docker', image: 'docker:1.12.6', command: 'cat', ttyEnabled: true),
    containerTemplate(name: 'sonarqube', image: 'sonarsource/sonar-scanner-cli:latest', command: 'cat', ttyEnabled: true),
    containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.3', command: 'cat', ttyEnabled: true)

],
volumes: [
   hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
]) {
  node(label) {
    def myRepo = checkout scm
    def gitCommit = myRepo.GIT_COMMIT
    def gitBranch = myRepo.GIT_BRANCH
    def shortGitCommit = "${gitCommit[0..10]}"
    def previousGitCommit = sh(script: "git rev-parse ${gitCommit}~", returnStdout: true)



    stage('sonar-scanner') {
     container('sonarqube') {
       sh "/opt/sonar-scanner/bin/sonar-scanner -X -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin"
      }
  }


}

}

【问题讨论】:

  • Jenkins 是否在 docker 容器中执行构建?
  • 是的,我在管道脚本中使用 pod 容器模板,我应该在这里更新我的脚本吗?
  • 嗨,Ale,你能帮我们因为这个问题而影响整个项目
  • 从容器内,主机不能作为本地主机访问。请改用外部 DNS 名称(或 ip)。另外,您是否阅读过此问答:stackoverflow.com/questions/38995148/…
  • 嗨,Alex,感谢您的快速响应,我在 /etc/hosts 文件中更新了 IP 地址,例如 10.0.0.4 localhost

标签: jenkins sonarqube


【解决方案1】:

由于您的 Jenkins 是在 cmets 中提到的 docker 容器中运行构建,因此解决方案是使用 IP 地址或本地 DNS 名称从构建脚本中访问 sonarqube,因为 localhost 不会解析到主机机器在 docker 容器内。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-27
    • 2017-09-29
    • 1970-01-01
    • 2021-07-19
    • 2018-08-14
    • 2019-11-11
    • 2016-10-15
    • 2012-06-07
    相关资源
    最近更新 更多