使用Jenkins在SonarScanner中读取超时

时间:2019-09-09 15:45:59

标签: docker jenkins sonarqube sonarqube-scan

在执行与 Jenkins 集成的 SonarScanner 分析期间,在控制台输出中会提示以下消息:

INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 3:33.658s
INFO: Final Memory: 5M/24M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Unable to load component class org.sonar.scanner.scan.ProjectConfiguration
ERROR: Caused by: Unable to load component class org.sonar.scanner.scan.ProjectServerSettings
ERROR: Caused by: Fail to request http://sonarqube:9000/sonarqube/api/settings/values.protobuf?component=AplicacaoTeste
ERROR: Caused by: timeout
ERROR: Caused by: Read timed out

OBS:我同时将Docker用于JenkinsSonarQube

来自sonar.properties的自定义值:

sonar.jdbc.username=YYYY
sonar.jdbc.password=XXXX
sonar.jdbc.url=jdbc:postgresql://sonarqube_db:5432/YYYY
sonar.jdbc.maxActive=1000
sonar.jdbc.maxIdle=8
sonar.jdbc.minIdle=4
sonar.jdbc.maxWait=0
sonar.web.host=0.0.0.0
sonar.web.context=/sonarqube
sonar.web.port=9000

Docker撰写文件:

version: "3.7"
services:
  jenkins:
    image: jenkins/jenkins:lts-jdk11
    container_name: jenkins-container
    restart: always
    labels:
      br.com.topfornecedores.descricao: "Jenkins CI/CD"
    networks:
      - software_qa
    volumes:
      - ./Jenkins/volumes/home:/var/jenkins_home
    expose:
      - 8080 
      - 50000
    ports:
      - 8088:8080 
      - 50055:50000
    depends_on:
      - sonarqube
  sonarqube_db:
    build: ./SonarQube_PostgreSQL
    container_name: sonarqube_db-container
    restart: always
    labels:
      br.com.topfornecedores.descricao: "Banco de dados do SonarQube"
    volumes:
      -  postgresql-volume:/var/lib/postgresql/data
    expose:
      - 5432
    ports:
      - 5432:5432
    networks:
      - software_qa 
    healthcheck:
      test: ["CMD", "pg_isready -U postgres"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 40s
  sonarqube:
    build: ./SonarQube
    container_name: sonarqube-container
    restart: always
    labels:
      br.com.topfornecedores.descricao: "SonarQube análises de qualidade de código e segurança"
    volumes:
      - "./SonarQube/volumes/conf:/opt/sonarqube/conf"
      - "./SonarQube/volumes/data:/opt/sonarqube/data"
      - "./SonarQube/volumes/logs:/opt/sonarqube/log"
    environment:
      - SONARQUBE_JDBC_URL=jdbc:postgresql://sonarqube_db:5432/sonardb
      - SONARQUBE_JDBC_USERNAME=sonarusuario
      - SONARQUBE_JDBC_PASSWORD=sonarusuariosenha
    expose:
      - 9000
    ports:
      - 9000:9000
      - 9002:9002
    depends_on:
      - sonarqube_db
    networks:
      - software_qa
networks:
  software_qa:
    driver: "bridge"
volumes:
    postgresql-volume:
      name: postgresql-volume

我可以在浏览器中访问URL:http://sonarqube:9000/sonarqube/api/settings/values.protobuf?component=AplicacaoTeste,没关系。

版本
SonarQube:7.9.1
SonarScanner Jenkins插件:2.6.1
詹金斯:lts-jdk11
Docker Windows桌面:2

此错误是为什么引起的?

1 个答案:

答案 0 :(得分:1)

您的数据库容器在docker-compose中有所不同,在URL中也有所不同,这就是为什么您超时的原因。

  sonarqube_db:
    build: ./SonarQube_PostgreSQL
    container_name: sonarqube_db-container

错误日志为

http://sonarqube:9000/sonarqube/api/settings/values.protobuf?component=AplicacaoTeste
ERROR: Caused by: timeout ```

您需要更新

SONARQUBE_JDBC_URL=jdbc:postgresql://sonarqube_db:5432/sonardb

SONARQUBE_JDBC_URL=jdbc:postgresql://sonarqube_db-container:5432/sonardb

sonarqube 相同,您正在为容器分配一个名称,因此要从其他容器访问时应使用sonarqube-container

  sonarqube:
    build: ./SonarQube
    container_name: sonarqube-container

喜欢

ERROR: Caused by: Fail to request http://sonarqube:9000/sonarqube/api/settings/values.protobuf?component=AplicacaoTeste

将此更改为

http://sonarqube-container:9000/sonarqube/api/settings/values.protobuf?component=AplicacaoTeste