I'm using Jenkins+Jacoco+Sonarqube to test my code. In Jenkins, my mvn command is:
mvn clean install sonar:sonar.
After code build in Jenkins, I am able to see the code coverage in Jenkins.
But I cannot get proper coverage percentage in SonarQube.
This could be a source path issue, maybe you don’t analyze the same sources. Do you have any excluded source files in Jacoco and Jenkins that you didn’t exclude in SonarQube properties, or vice versa?
Your command doesn't include the generation of the reports. Try instead:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar
Breaking it down:
mvn invoke the build system
clean delete all old build output
org.jacoco:jacoco-maven-plugin:prepare-agent turn on test reporting
install build and install the result in the local Maven repository
sonar:sonar run a SonarQube analysis
Related
Jenkins Version : 2.176.2
Executing Selenium tests via Jenkins : Ecplsie+mvn+Jenkins
Selenium Workspace Folder : C:\Users\admin\eclipse-workspace\ACA
The actual location of the testng-results.xml: C:\Users\admin\eclipse-workspace\ACA\target\surefire-reports\testng-results.xml
Jenkins Insatlled / Home Directory: C:\Program Files (x86)\Jenkins
Building in workspace C:\Program Files (x86)\Jenkins\workspace\ACATestAutomationJob
Executing Maven: -B -f C:\Users\admin\eclipse-workspace\ACA\pom.xml clean install
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **/target/surefire-reports/testng-results.xml
Did not find any matching files.
How do i make jenkins locate this testng-results.xml?
Thanks,
Raj
Look into Jenkins Console Output, it should report where the build is running (so called WORKSPACE) and where TestNG Results Plugin attempts to locate the results file:
The path to the TestNG results file must be relative to the WORKSPACE and have the syntax of Ant FileSet
If you're uncertain regarding how to properly build the path to the test artifacts - post the full paths to WORKSPACE and the testng-results.xml / emailable-report.html and we will help you to come up with the correct definitions.
In the meantime you could use wildcard paths like:
**/testng-results.xml
so Jenkins will scan its WORKSPACE recursively looking for the testng-results.xml file in all available locations
Your install command also looks suspicious, normally you should not be putting your test artifacts to the Maven repository so you might want to use mvn test or mvn verify instead.
More information:
Turbo Boost Your Digital App Test Automation with Jenkins
https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
I want to do static code analyze for typescript Jenkins job using SonarQube. I can do it by installing tsLint lib to my project and compile gulp file in Jenkins, but I think it is not a developer friendly method. Is there any maven command can run on Jenkins shell to analyze typescript code in SonarQube.
you can use this sonarqube plug-in https://github.com/Pablissimo/SonarTsPlugin... This plugin works with tslint but it is no official sonarqube plugin... In my case it works perfectly
I'm using SonarQube and Jenkins. In Jenkins, I check the unit tests with nUnit and the coverage with opencover. The opencover's report is displayed in Sonar but the nunit's report is not. The Unit Tests count is not even displayed in the home page of the project.
Here is what I do :
Build my VisualStudio project with MSBuild
Run nunit and opencover with a batch command line
Run SonarQube scanner's analysis
Package the project
The Step 2's command line :
MKDIR "%WORKSPACE%\reports"
MKDIR "%WORKSPACE%\reports-history"
SET COV_PTH="D:\Programmes\opencover.4.5.3522"
SET TOOL_PATH="D:\Programmes\NUnit-2.6.4"
SET RPT_PATH="D:\Programmes\ReportGenerator"
copy src\Foo.Bar.Tests\app.config build\Foo.Bar.Tests.dll.config
%COV_PTH%\OpenCover.Console.exe "-filter:+[Foo.Bar*]* -[Foo.Bar.Tests]* -[Foo.Bar.Service]* -[Foo.Bar.Domain]* -[Foo.Bar.Dal]Foo.Bar.Dal.Dao.* -[Foo.Bar.Controller]Foo.Bar.Controller.*Comparer -[Foo.Bar.Controller]Foo.Bar.Controller.External.*" -register "-target:%TOOL_PATH%\bin\nunit-console.exe" -targetargs:"build\Foo.Bar.Tests.dll /noshadow /result=reports\TestResult.xml" -output:reports\opencovertests.xml
%RPT_PATH%\ReportGenerator.exe "-reports:reports\opencovertests.xml" "-targetdir:reports-ReportGenerator" "-historydir:reports-history"
The Step 3's parameters :
sonar.projectKey=FooBar
sonar.projectName=FooBar
sonar.projectVersion=%SVN_REVISION%
sonar.sources=src/Foo.Bar.Controller, src/Foo.Bar.Dal, src/Foo.Bar.Domain, src/Foo.Bar.Fichier, src/Foo.Bar.Generation, src/Foo.Bar.Reporting, src/Foo.Bar.Service, src/Foo.Bar.Web
sonar.binaries=Build/Foo.Bar.Controller.dll, Build/Foo.Bar.Dal.dll, Build/Foo.Bar.Domain.dll, Build/Foo.Bar.Service.dll, Build/Foo.Bar.Fichier.exe, Build/Foo.Bar.Generation.exe, Build/Foo.Bar.Reporting.exe
sonar.tests=src/Foo.Bar.Tests
sonar.cs.opencover.reportsPaths=reports/opencovertests.xml
sonar.cs.nunit.reportsPaths=reports/TestResult.xml
EDIT
I also tried the following process (same results) :
Prepare SonarQube scanner's analysis
Build my VisualStudio project with MSBuild
Run nunit and opencover with a batch command line
End SonarQube scanner's analysis
Package the project
END EDIT
The nUnit's report is well generated in workspace/reports/TestResult.xml.
I tested the analysis generation by command line and via the sonarqube plugin for jenkins. I got the same results.
Can you see anything wrong?
Is there any SonarQube's logs that I could checked ?
I am using Jenkins 2.10, MSBuild 12, SonarQube 5.6, SonarQube scanner for Jenkins plugin 2.4.3, opencover 4.5 and nunit 2.6.4
EDIT
I updated my config : Jenkins 2.18, MSBuild 14, SonarQube scanner for Jenkins plugin 2.4.4. Same results.
END EDIT
Take a look at: SonarQube documentation: Unit Test Execution Results Import (C#, VB.NET)
It says:
Drilldown on Test Execution Results is not supported
My understanding is that you can only see the results (number of Tests passing, errors, etc) but not detail from the tests.
You also ask about Logs. You have:
Jenkins Job log
SonarQube Background tasks: Login as Admin -> Administration -> Projects -> Background tasks -> far right of each execution ---> http://docs.sonarqube.org/display/SONAR/Background+Tasks
SonarQube logs: sonar_install_directory\logs
I migrated a large Maven project with submodules to sbt and got it to build correctly with Jenkins and its sbt plugin. I run sbt compile test. As I understand, sbt compiles incrementally by default. Is it also possible to have it run only tests affected by the changed classes?
Yes, using testQuick, see the docs for more information.
Problem
I have just installed the Sonar Jenkins plugin. I went into my configured job (a free style job) that produces a WAR file artifact through an ANT build and did as follows:
Check the Sonar checkbox. (No problems here)
Configure the install dir of sonar (No problems here)
Checked the checkbox that states: "Check if this project is NOT built with maven 2" (I am confused here)
I have checked that box because I am not using maven for build, I am using ANT but it still asked me for required properties that resemble a lot MVN such as: Organization id, project id, project name, project version, source directories... etc..
So I have filled those as well. When I click the play button "Build Now" the build seems to be running fine as it always had prior to sonar installation but it fails at the very end because its trying to execute MAVEN.
See as follows:
$ mvn -f /root/.jenkins/jobs/HRDA/workspace/pom.xml -e -B sonar:sonar
FATAL: command execution failed
java.io.IOException: Cannot run program "mvn" (in directory "/root/.jenkins/jobs/HRDA/workspace"): java.io.IOException: error=2, No such file or directory
Questions
Why is Sonar trying to execute Maven if I have checked the box that said check this box if you do NOT use Maven 2?
Can I make use of this Sonar plugin if my apps are built with ANT, GANT, GRADLE?
Do I have to reconvert my apps to use MVN builds?
Thanks,
- Dario
Like Oers suggested on my question comments if you are using ANT as a build script in your CI server (Jenkins in my case) you will have to use the SONAR-ANT-TASK to generate Sonar reports, do as follows:
Download MySQL or any other Sonar supported RDBMS such as Postgres, Oracle, etc..'
Download and Install sonar server.
go to (sonar installation folder)/extras/database/mysql and run the create_database.sql script.
I had to run an extra sql statement in my case using mysql, you can see here Unable to access Sonar MySQL database Caused by: java.sql.SQLException: Access denied for user 'sonar'#'glassfishdev.ccs.local' (using password: YES)
Start Sonar by typing ./sonar.sh start
Add the sonar ant task to your build script. You can follow this template http://docs.codehaus.org/display/SONAR/Analyse+with+Ant+Task+1.0
DO NOT check the sonar check box in your Configure screen if you have the Hudson Sonar plugin for installed, as this plugin only works with Maven projects.
Click the "Build Now" button. If everything above has been done correctly you should be able to see the reports at http://ipaddressofmachinesonarisinstalled:9000/
Hope this helps,
-Dario