Jenkins + Sonar - maven

I have a project Pensky with two build Jobs on my Jenkins Server. The First Build job does maven build and collects JaCoCo Code coverage report on Post Build Action.
My Second Build Job runs Sonar Analysis on my project. I would like to reuse/feed the JaCoCo code coverage report into my Sonar. But, unable to do so. I see the below message in my build job console
"Project coverage is set to 0% as build output directory does not
exist:"
The sonar job is looking for 'classes' folder in the .sonar directory (in the jenkins job directory).
Can anyone guide me how to feed the report into Sonar. Thank you
This is my sonar.properties
sonar.projectKey=Pensky
sonar.projectName=Pensky
sonar.projectVersion=1.1
sonar.projectDescription= GE Pensky
sonar.sources=src/main/java
sonar.tests=src/test/java
sonar.language=java
sonar.my.property=value
sonar.forceAnalysis=true
sonar.jacoco.reportPath=target/jacoco.exec

You haven't set the "sonar.binaries" property to point to the build directory (= "target/classes" if you compile it with Maven).

First of all, you should to copy the folder target of the first job in order to save time. If you do that, you have in the workspace of the job, all the binaries and the jacoco.exec file.
Then, you have to set the folder of the tests result.
sonar.junit.reportsPath=target/surefire-reports(or other)
sonar.jacoco.ReportPath=target/jacoco.exec
And finally, you have to set the binaries folder.
sonar.binaries=target/classes
Hope I have been helpful.

Related

TeamCity Artifact Dependencies target directory same source directory

I have 4 teamcity build configuration like this
build, test, static analysis is parallel, sonar wait 3 steps finish and use test results and analysis results for create sonar report.
build ------------|
test -------------|
static analysis --|
|----- Sonar report
I want use test step results (.exec file for coverage) for sonar step, as I understand, i need use artifact dependencies for this, BUT test step create a many files in build directories like this
/{moduleName}/build/jacoco/*.exec
i have >100 modules
how i can setup artifact dependencies for files transfer to next step without change directory like this -
(source dirs) (target dirs)
**/build/jacoco/*/*.exec => **/build/jacoco/*/*.exec
i can't write this paths in manual
UPD: QUESTION RESOLVED
if use pattern in artifact publish like +:**/build/jacoco/*/*.exec (without target), all artifacts save position in directory tree

Showing 0% Coverage in SonarQube (integration with Teamcity for .Net Project)

I have configured the Build steps as below
Created another Build Configuration (e.g. named "Send to SonarQube") and added the dependency on initial configuration
An artifact dependency for ".teamcity/.NETCoverage/dotCover.dcvr" file and getting artifacts from "Build from the same chain".
In the new configuration ("Send to SonarQube") added a Command Line step with the following script:
%teamcity.dotCover.home%\dotCover.exe report /ReportType=HTML /Source="dotCover.dcvr" /Output="dotCover.html"
Added SonarQube Runner to the new configuration and added additional command line argument with "-Dsonar.cs.dotcover.reportsPaths=dotCover.html"
Please suggest
Note: When i have checked the dotCover.html the coverage is showing perfectly. But the sonarqube is showing as 0% covered
Since you are using build chains, you are probably switching directories and SonarQube uses absolute paths. To confirm this, look at the html/[nnn].html files in your working directory. In html -> head -> title, does the absolute path match the source code in your current working directory when you run the report command?
So to summarize, in your "Send to SonarQube", you need to ensure:
You have your source code in the working directory
Your individual [nnn].html files have titles with absolute paths matching the source code in your working directory.
There are a few ways to ensure #2:
Way #1
Tell TeamCity to run all snapshot dependencies on the same agent.
Make sure your VCS setup is exactly the same. (For myself, I had excluded some folders in my "Send To SonarQube" equivalent, and that caused a different working directory)
Way #2
Override the Checkout Directory in your VCS setup for everything in the build chain to point to the same absolute directory.
(I haven't tried this, but it should work across agents since the agent name isn't in the directory path)

How to configure a sonar-project.properties file for code coverage?

Current my scanner is running through and only scanning the parent and skipping the rest of my nested files. If I run sonarlint (using the cli and specifying some test and source files) , it tries to analyze 37k files instead of the few I need. I have been able to skip ~3k files by adding the <sonar.skip>true</sonar.skip> property to a pom file. However, I still can't configure the project to run across certain sub-folders and print out some kind of code coverage test. (Is JaCoCo needed for the latest version(6.3,0)? Or can code-coverage be handled through some configuration?).
If Sonar seems to be analyzing too many files, it is probably because you had not set the sonar.sources=src/main/java in your sonar-project.properties file, so it defaults to the basedir and includes everything.
SonarQube can't do code-coverage itself, it just reports on coverage-reports from a tool like JaCoCo. It is funny they don't clarify these things in https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner --but with enough digging, you can find good info on that site.

Failed to publish TestNG Report in Jenkins

I have used Maven project with Selenium & TestNG to create automated scripts which I want to execute from Jenkins. In Jenkins I have added the TestNG plugin to publish the TestNG report. But it is not getting displayed. I'm getting the below mentioned error.
Error:
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.
Finished: SUCCESS
Actual path of the TestNG report file:
E:\STUDY_MATERIAL\JAVA\WORKSPACE\SeleneniumFrameWork\target\surefire-reports\testng-results.xml
I have tried the following options but didn't work out for me.
Tried giving the full path of the TestNG report. Forward ans backward slash in the pattern.
I have tried different other options by changing the TestNG result file path but it's working for me.
Please share some inputs on how to resolve this issue.
"testng-results.xml" file is available in workspace. But it's failed to display the report. I have attached screenshot of Jenkins workspace and Console Output.
Note: I am using Jenkins 2.7.0 in Windows 10.
Jenkins Workspace
I have attached the Job configuration details of Jenkins.
Job Configuration Details
Few checkpoints :
1. Check if testng is producing this file at the specified location : /target/surefire-reports/testng-results.xml
2. TestNG needs to be configured to generate xml report
If this file is there, pass path in file locator as :
target/surefire-reports/testng-results.xml
Hopefully, you will get results on jenkins if everything mentioned above is correct.

TeamCity export CoverageReport.xml to a predefined directory

I am trying out TeamCity for our CI.
We have a build step running NUnit for unit test and dotCover for code coverage. The process went through fine, but im just wondering if it is possible to export the Build Log and the dotCover's CoverageReport.xml to a predefined directory on the local machine.
or maybe even export all the artifacts and reports used in the build to a local folder.
Just add a build step ( command line ) that will copy over the reports that you need to the desired location locally.

Resources