I am running my analysis with Maven, triggered by a Jenkins job. As a DBMS i am using MySQL thats running on the same server as Jenkins does but my sonar instance is running on my local machine (connected to the MySQL DB). I don't want to run it on the server, yet. I would prefer to not run it at all for the time being.
Is it possible to run the analysis without a running sonar instance? Why do I have to configure the server URL (the login too) in both, the Jenkins plugin and the pom.xml?
The described architecture on SonarQube Platform Overview indicates that the analyser and server are not directly connected (only via DB).
When i try to run the analysis from Jenkins with no Server URI the build process is throwing the following message:
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.2:sonar (default-cli) on project xxx: SonarQube server can not be reached at http://localhost:9000. Please check the parameter 'sonar.host.url'. Connection refused -> [Help 1]
Thats exactly what i expected, he is trying to connect to the SonarQube instance that i did not want to run.
You don't have to configure the URL to Sonar in the POM if you are using the Sonar plugin to push results to Sonar.
Sonar 'instance' you are referring to is for you to visually see the post code analysis result. If you don't have the Sonar UI web application installed, code analysis is still run by Maven either through Jenkins or your IDE or in the command prompt/shell.
Related
The company I work for uses SonarQube as part of our CI build.
I have configured my settings.xml file according to: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/
I am pointing my local build at the same SonarQube server that is used by our CI build.
My build fails on the CI server as a result of the SQ analysis.
When I perform mvn sonar:sonar on my machine I am expecting a failed build with some helpful error messages. Instead, the build succeeds.
What am I doing wrong?
Which versions am I using (SonarQube, Scanner, Plugin, and any relevant extension):
SonarQube 7.9.1 (on a remote server)
Sonar maven plugin 3.7.0.1746 (in my pom.xml file)
Jenkins 2.222.1 (local server)
Maven 3.6.0
What am I trying to achieve:
I want to perform an analysis with a Jenkins Pipeline with my remote server
What have I tried so far to achieve this :
I have succeed to do an analysis with my IDE (intelliJ) and it works with the command :
mvn -B sonar:sonar
After that, the server note the last analysis with the Quality Gate.
Nevertheless, it does not work with my Jenkins Pipeline.
I do not understand why it works with the IDE and not with Jenkins.
I have put in my pom.xml a sonar.login which is a specific user token. This user has the right to execute an analysis on this particular project. In my ~/.m2/settings.xml, I have put the sonar.host.url.
I also tried to set up manually a SonarQube server in Jenkins (in system configuration). I put there the url and my token thanks to a secret text but it does not work to.
I have also generated a Webhook but this is for the qualitygate variable in the pipeline and I don’t think it matters here.
I don’t know what to test now…
Any idea ?
Thanks
It is ok now : I have added on a sonar installer in the settings. In addition I move the sonar.host.url from ~/.m2/settings.xml to my pom.xml file.
I'm having a confusing problem with SonarQube 5.6 when trying to run an analysis with the sonar-maven-plugin 3.2 on a Java 8/Maven 3 project.
The error message is the following:
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin: 3.2:sonar (default-cli) on project YYY: Unable to execute SonarQube: Fail to download libraries from server: Status returned by url [XXX/sonarqube/batch_bootstrap/index] is not valid: [401] -> [Help 1]
The account I'm using has the permission "Execute Analysis" (it's in the group sonar-administrators) and the credentials are working when logging in via browser. Even the connection test of the SonarLint Eclipse plug-in was successful.
The problem was that I tried to reach the SonarQube server using an external URL instead of a local one. Seems to have to do with HTTPS or something like this. Using the local URL (http://sonarqube:9000/sonarqube) it now works.
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 running maven with sonar. Since I activated authentication on sonar for security purposes, since then I got the following error:
[ERROR] Can´t access to Sonar or project doesn't exist on Sonar instance. HTTP KO to http://localhost:9000/api/resources?resource=com.myproject.soft:soft&depth=0&format=xml
java.io.IOException: Can´t access to Sonar or project doesn't exist on Sonar instance.
at org.sonar.report.pdf.util.SonarAccess.getUrlAsDocument(SonarAccess.java:132)
at org.sonar.report.pdf.entity.Project.initializeProject(Project.java:98)
according to http://docs.sonarqube.org/display/SONAR/Analyzing+with+Maven I should use the following parameters:
-Dsonar.login=login -Dsonar.password=password
Those settings are not working for me.
The full command I am using is:
mvn install sonar:sonar -Dsonar.login=login -Dsonar.password=password
This is a limitation of the PDF Report Plugin that is developed by Klicap:
http://jira.codehaus.org/browse/SONARPLUGINS-1510
If you remove this plugin, then everything should be back to normal.
We have the same problem and resolved it by adding some credentials. Tested on Sonar 3.7 and Sonar PDF Plugin 1.3
In eclipse put this as your maven Goals:
org.codehaus.sonar-plugins.pdf-report:maven-pdfreport-plugin:1.3:generate -Dsonar.host.url=http://localhost:9000 -Dreport.type=executive -Dsonar.pdf.username=admin -Dsonar.pdf.password=admin