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):
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.
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:
it works fine.
Related
I am using SonarQube version 6.7 for running analysis of Maven projects using the command mvn clean verify sonar:sonar from the project directory using command prompt and get the results. The sonar configurations in settings.xml for maven (v3.5.3) are added respectively.
In Jenkins (version 2.161), I have installed SonarQube Scanner for Jenkins (v2.8.1) plugin. The SonarQube Server configuration is configured as below.
In the Jenkins maven project, I have configured the post steps as below.
I have checked the Prepare SonarQube Scanner environment in the Build Environment section and the Build goal is -e clean verify sonar:sonar.
My issue is, when the SonarQube analysis for a maven project is triggered through command prompt using the command mvn clean verify sonar:sonar, I am getting the results as expected. But when the Jenkins job is triggered with the configurations above for the same maven project, the results are different and incorrect. What am I missing?
P.S- In the Post-build Actions, I can see the SonarQube analysis with maven is deprecated.
Thanks in advance.
You use different scanners. First you used SonarScanner for Maven (mvn sonar:sonar). Next you used Basi SonarScanner, which requires manual configuration of all options.
The best option to sole it is always use the same scanner. You have Maven project, so you can enable Prepare SonarQube Scanner environment in Build Environment, and next execute Sonar goal $SONAR_MAVEN_GOAL in Build.
I am doing a sonar analysis from my machine using a sonar instance on a remote server.
Local machine: Window7, apache-maven-3.2.5
Remote sonarcube server: sonarcube Version 3.7.3
I am using below command from command prompt:
mvn sonar:sonar -Dsonar.jdbc.url=<jdbcurl> -Dsonar.host.url=<sonarserver url>
I have defined a sonar profile for running the same
Whe I run the said mvn command, then I am getting below error:
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project builder-allmodules: Can not execute SonarQube analysis: Can not execute Findbugs: java.lang.RuntimeException: edu.umd.cs.findbugs.NoClassesFoundToAnalyzeException: No classes found to analyze in mymavenproject\target\classes *xyz.jar *F:\m2\repository\commons-io\commons-io\2.4\commons-io-2.4.jar *abc.jar *lmn.jar aaa.jarbbb.jar *ggg.jar
mymavenproject\target\classes: doesn't have any classes, instead, there is bundled jar at mymavenproject\target\ which contains all the classes
Also, another issue is that it is trying to analyze all the dependent jars also which should not be the case as I need sonar analysis for my project only
Can you let me know what I might be missing?
Because you've included FindBugs rules in your analysis profile, you're required to provide unbundled classes to the analysis.
I am trying to run sonar sonar:sonar by integrating sonarqube and jenkins. While doing, am getting the below error.
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project iwm_common: Can not execute SonarQube analysis: org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext -> [Help 1]
Jenkins version - 1.612
Sonarqube version - 3.6
JDK-1.7.0_76
Maven - 3.1.1
Jenkins WAR is deployed in server A and sonarqube is deployed in server B. I have not installed sonar-jenkins plugin in Jenkins.
Can anyone let me know whether sonar-jenkins plugin is mandatory to be installed in jenkins to integrate jenkins with any sonar server (eg:sonarqube).
If the answer is YES, then after installation of the required plugin, will adding the sonar server (eg:sonarqube) information under Manage Jenkins -> Configure system -> sonar resolve the above error ?
The error is related to sonar-maven-plugin and this plugin is not used in any of the project's pom.xml. Can anyone please explain whether this plugin gets referred as a part of sonar:sonar goal. Thanks.
The versions you specified are not compatible for running sonar analysis.
Please upgrade SonarQube version (current is 5.1.1) which requires
Java 1.7-1.8
SonarQube 5.0 or 5.1.1
Sonar-runner 2.4
Using latest version of sonarqube resolved the issue mentioned.
I receive error Dependency META-INF/lib/bcel-findbugs-6.0.jar can not be found in sonar-findbugs-plugin-3.0.jar during build on jenkins for all projects using sonarqube:
[INFO]
[INFO] --- sonar-maven-plugin:2.4:sonar (default-cli) # tig-parent ---
[INFO] SonarQube version: 4.4
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: /opt/jenkins/workspace/TIG nightly sonar/target/sonar
INFO: SonarQube Server 4.4
[INFO] [16:54:50.855] Load global settings
[INFO] [16:54:51.042] User cache: /var/run/tomcat/jenkins-master-dev.mycompany.com_00/.sonar/cache
[INFO] [16:54:51.055] Install plugins
[ERROR] Dependency META-INF/lib/bcel-findbugs-6.0.jar can not be found in sonar-findbugs-plugin-3.0.jar`
I am not aware of any changes in project sonar configuration, jenkins or sonarqube server. I checked that sonar-findbugs-plugin-3.0.jar plugin contains bcel-findbugs-6.0.jar library. I reinstalled the findbugs plugin without effect.
. You mean that it did work before but it does not work anymore?
. When you say that you are not aware of any changes in configuration, you mean there has not been any upgrade of software?
. No modification in your environment (Java version, path, etc.)
The solution was to delete sonar cache: /var/run/tomcat/jenkins-master-dev.mycompany.com_00/.sonar/cache
I am getting following error when building a project in jenkins:
ERROR: A Maven installation needs to be available for this project to be built.Either your server has no Maven installations defined, or the requested Maven version does not exist.
[cloudbees-deployer] Skipping deployment as build result is FAILURE
Finished: FAILURE
In Jenkins settings, I tried both options: automatic installation from apache as well as use pre-installed maven on dev#cloud.
What might be missing?