1、首先在jenkins所在机器的的maven配置文件(settings.xml)里做如下配置:
1 <profile> 2 <id>sonar</id> 3 <activation> 4 <activeByDefault>true</activeByDefault> 5 </activation> 6 <properties> 7 <!-- EXAMPLE FOR MYSQL --> 8 <sonar.jdbc.url>jdbc:mysql://x.x.x.x:3306/sonarsec?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance</sonar.jdbc.url> 9 <sonar.jdbc.driverClassName>com.mysql.jdbc.Driver</sonar.jdbc.driverClassName> 10 <sonar.jdbc.username>user</sonar.jdbc.username> 11 <sonar.jdbc.password>password</sonar.jdbc.password> 12 <sonar.host.url>http://x.x.x.x:9000</sonar.host.url> 13 </properties> 14 </profile>
2、在jenkins的项目配置里
mvn sonar:sonar -Dsonar.branch=master-test -Dsonar.host.url=http://x.x.x.x:9000 -Dsonar.projectKey=test -Dsonar.projectName=test -Dsonar.projectVerision=1.0