2
votes

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 configuration

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

Build enviroment

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

Build step

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?

1
I strongly update to update your version to 5.6.3 (LTS)Teryk - SonarSource
@Teryk - SonarSource Team: I have already an instance of SonarQube 5.6.3 for our Java 8 build jobs. But I need our old instance of SonarQube 4.3 for our Java 6 and Java 7 build jobs.dur
You can analyze Java 6 and 7 projects on SQ 5.6+. Compile with whatever you like, but run the analysis with Java 8G. Ann - SonarSource Team
@G. Ann - SonarSource Team: Unfortunately Jenkins has no feature to run build steps with different JDK/JREs. I can only choose one Java version for the whole build job.dur
@G. Ann - SonarSource Team: In Hudson I could run SonarQube scan as a post build action and use a different JDK/JRE, but that is not possible with Jenkins.dur

1 Answers

3
votes

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. This feature is not needed if you're using "SonarQube Scanner" or "SonarQube Scanner for MSBuild" build steps.

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

enter image description here it works fine.