Ricardo
Ricardo

Reputation: 699

Read timed out in SonarScanner using Jenkins

During execute a SonarScanner analysis integrated with Jenkins, it's prompted in console output the following message is displayed:

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: I'm using Docker for both Jenkins and SonarQube

Custom values from 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 compose file:

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

I can access the URL: http://sonarqube:9000/sonarqube/api/settings/values.protobuf?component=AplicacaoTeste in browser and it's OK.

Versions:
SonarQube: 7.9.1
SonarScanner Jenkins Plugin: 2.6.1
Jenkins: lts-jdk11
Docker Windows Desktop: 2

This error is caused Why?

Upvotes: 0

Views: 1038

Answers (1)

Adiii
Adiii

Reputation: 60164

Your DB container is different in docker-compose and in the URL is different so that is why you got timeout.

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

As the error log is

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

You need to update

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

to

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

Same case for sonarqube, you are assigning a name to you container so you should use sonarqube-container when you want to access from other containers.

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

like

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

change this to

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

Upvotes: 1

Related Questions