Jenkins和Sonar Docker无法连接

时间:2018-10-28 23:49:15

标签: docker jenkins sonarqube

我的Jenkins无法连接到Sonar,两者都在同一个Docker Compose中。

[argentum-web] $ /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/bin/sonar-scanner "mvn sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login=0f9b5f4d4219201023539244b22daf5bb97c8f10" -Dsonar.host.url=http://localhost:9000 ******** -Dsonar.projectBaseDir=/var/jenkins_home/workspace/argentum-web
INFO: Scanner configuration file: /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.2.0.1227
INFO: Java 1.8.0_192 Oracle Corporation (64-bit)
INFO: Linux 4.15.0-20-generic amd64
INFO: User cache: /var/jenkins_home/.sonar/cache
ERROR: SonarQube server [http://localhost:9000] can not be reached
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 1.868s
INFO: Final Memory: 3M/59M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Unable to execute SonarQube
ERROR: Caused by: Fail to get bootstrap index from server
ERROR: Caused by: Failed to connect to localhost/127.0.0.1:9000
ERROR: Caused by: Connection refused (Connection refused)
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succedeed?
ERROR: SonarQube scanner exited with non-zero code: 1
Finished: FAILURE

docker-compose:

version: '2'

services:

  jenkins:
    image: jenkins/jenkins:lts
    volumes:
    - /home/rafaelvicio/Dev/jenkins_example/jenkins:/var/jenkins_home/workspace/
    networks:
      - jenkinsexample
    ports:
    - 8080:8080
    - 50000:50000

  sonarqube:
    container_name: sonarqube
    image: sonarqube
    networks:
      - jenkinsexample
    ports:
     - 9000:9000

networks:
  jenkinsexample:
    driver: bridge

Sonarqube任务:

  

mvn sonar:sonar -Dsonar.host.url = http://localhost:9000   -Dsonar.login = 0f9b5f4d4219201023539244b22daf5bb97c8f10

1 个答案:

答案 0 :(得分:0)

将声纳URL更改为以下-

mvn sonar:sonar -Dsonar.host.url=http://sonarqube:9000 ....

Jenkins容器通过服务名称即sonarqube来了解Sonar。