[英]How to connect Jenkins with SonarQube 4.3?
I try to migrate my build jobs from Hudson to Jenkins (version 2.32.1). 我尝试将我的构建工作从Hudson迁移到Jenkins(2.32.1版)。 The Maven build works fine, but the Maven build step for SonarQube doesn't work.
Maven构建工作正常,但是SonarQube的Maven构建步骤不起作用。 I use Jenkins SonarQube Plugin version 2.5.
我使用Jenkins SonarQube插件2.5版。
My SonarQube configuration (following Adding SonarQube Scanner ): 我的SonarQube配置( 添加SonarQube Scanner之后 ):
My build environment (following Configuring a SonarQube Scanner using environment variables ): 我的构建环境(在使用环境变量配置SonarQube扫描仪之后 ):
My Maven build step (following Analyzing with SonarQube Scanner for Maven ): 我的Maven构建步骤(在使用SonarQube Scanner for Maven进行分析之后 ):
Jenkins console log: Jenkins控制台日志:
[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). 日志显示,詹金斯使用了错误的数据库URL(H2而不是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:
我查看了Jenkins SonarQube插件的源代码 (因为找不到文档),并找到了暴露的环境变量的列表:
Inject environment variables related to the chosen SonarQube installation.
注入与所选SonarQube安装相关的环境变量。
The following variables may be set depending on the configuration:根据配置,可以设置以下变量:
- SONAR_HOST_URL
SONAR_HOST_URL
- SONAR_AUTH_TOKEN
SONAR_AUTH_TOKEN
- SONAR_LOGIN
SONAR_LOGIN
- SONAR_PASSWORD
SONAR_PASSWORD
- SONAR_JDBC_URL
SONAR_JDBC_URL
- SONAR_JDBC_USERNAME
SONAR_JDBC_USERNAME
- SONAR_JDBC_PASSWORD
SONAR_JDBC_PASSWORD
- SONAR_EXTRA_PROPS
SONAR_EXTRA_PROPS
- SONAR_MAVEN_GOAL - supplies the correct Maven goal based on the "Version of sonar-maven-plugin" specified for the SonarQube instance.
SONAR_MAVEN_GOAL-根据为SonarQube实例指定的“声纳-maven-插件的版本”提供正确的Maven目标。
These variables are useful when configuring a SonarQube analysis using standard build steps such as Maven, Gradle, Ant, and command line scripts.使用标准构建步骤(例如Maven,Gradle,Ant和命令行脚本)配置SonarQube分析时,这些变量很有用。
This feature is not needed if you're using "SonarQube Scanner" or "SonarQube Scanner for MSBuild" build steps.
如果您使用“ SonarQube Scanner”或“用于MSBuild的SonarQube Scanner”构建步骤,则不需要此功能。
After adding -Dsonar.jdbc.url=$SONAR_JDBC_URL
to my build step: 将
-Dsonar.jdbc.url=$SONAR_JDBC_URL
添加到我的构建步骤后:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.