简体   繁体   中英

How to connect Jenkins with SonarQube 4.3?

I try to migrate my build jobs from Hudson to Jenkins (version 2.32.1). The Maven build works fine, but the Maven build step for SonarQube doesn't work. I use Jenkins SonarQube Plugin version 2.5.

My SonarQube configuration (following Adding SonarQube Scanner ):

SonarQube配置

My build environment (following Configuring a SonarQube Scanner using environment variables ):

建立环境

My Maven build step (following Analyzing with SonarQube Scanner for Maven ):

建立步骤

Jenkins console log:

[INFO] SonarQube version: 4.3
INFO: Default locale: "en_US", source code encoding: "cp1252"
INFO: Work directory: /home/jenkins/.jenkins/jobs/test/workspace/target/sonar
INFO: SonarQube Server 4.3
[INFO] [15:34:56.104] Load batch settings
[INFO] [15:34:56.248] User cache: /home/jenkins/.sonar/cache
[INFO] [15:34:56.254] Install plugins
[INFO] [15:34:56.320] Install JDBC driver
[WARN] [15:34:56.329] H2 database should be used for evaluation purpose only
[INFO] [15:34:56.329] Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
[ERROR] Fail to connect to database

Logs show, that Jenkins used the wrong database URL (H2 instead of PostgreSQL).

What did I wrong?

I found a work-around. I looked at the source code of Jenkins SonarQube Plugin (because I couldn't find the documentation) and found a list of exposed environment variables:

Inject environment variables related to the chosen SonarQube installation.
The following variables may be set depending on the configuration:

  • SONAR_HOST_URL
  • SONAR_AUTH_TOKEN
  • SONAR_LOGIN
  • SONAR_PASSWORD
  • SONAR_JDBC_URL
  • SONAR_JDBC_USERNAME
  • SONAR_JDBC_PASSWORD
  • SONAR_EXTRA_PROPS
  • SONAR_MAVEN_GOAL - supplies the correct Maven goal based on the "Version of sonar-maven-plugin" specified for the SonarQube instance.

These variables are useful when configuring a SonarQube analysis using standard build steps such as Maven, Gradle, Ant, and command line scripts.

After adding -Dsonar.jdbc.url=$SONAR_JDBC_URL to my build step:

在此处输入图片说明 it works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM