Goal: to integarte sonarcube with current teamcity build config(java+ant)
Issue: Not sure how to include/specify the ant xml file(which build/runs the tests) in the sonar build step
What i have tried:
created a sonarcube runner build step which runs after my ant build step
i do see my project on the sonar server and i have the project key.it says “project is not analyzed yet”
Here are the docs on the SonarQube Scanner for Ant. You should be aware going in that the usage of this is not very Ant-y, and it can be tricky to set up properly. Another option is to exec the vanilla SonarQube Scanner
hi Ann thanks for the prompt reply. So heres where i am stuck .
What i have working:
I run the teamcity build with JACOCO coverage and it generates the coverage report on Team city.(its an index.html file)
What i want to achieve:
I want sonarcube to “see” this report generated in teamcity,which for the love of god i cant seem to get working.It just cant find the report! Also i get a warning saying “cant find classfile”. i do provide the -Dsonar.java.binaries value ,i guess i am messing that up maybe.
what i am not sure about:
1.If i can get code coverage by using Team citys in built Jacoco plugin then why do i need sonarcube?
2.Will sonarcube also again do its own code coverage? If so does it use JACOCO under the hood?
Hi Ann,
Thanks for the suggestions! Ok so heres where im still not able to convince myself…
Why do i need sonarcube for code coverage when i already get the code coverage report in Teamcity(using Teamcitys jacoco plugin)??
Also the project in teamcity is build via ANT in a TC config. I checked the temp directory on the TC agent host and found a path as below which did have the jacoco.exec.
/temptdirpath/JACOCOcoverage/jacoco.exec
How can i set a path to jacoco.exec if its dynamic??
Also I do see the jacoco.exec as an artifact in Team citys build but im guessing i cant reference that as its on the TC server.
First, I’ve never seen the TeamCity JaCoCo plugin’s coverage report, so… there’s that. But if all you care about is what’s already presented in that report, then I guess you don’t need SonarQube.
But you started this thread by asking about integration in general, not specifically about JaCoCo/code coverage, so I’ll assume that you have other reasons for trying to get started with SonarQube. And in that context, I’ll say that your primary motivation to get your JaCoCo report passed into analysis would be to have all your code quality data (and history/trends!) in one place.
Regarding your practical questions, I’ve never used TeamCity, but I would guess there’s some environment variable that holds the path to the temp directory your coverage report is generated to. So use that (presumed) env var in your configs for specifying the path to your .exec report.
hi Ann,
It was my assumption that Jacoco was the default tool used by sonar under the hood to do the analysis,which is why i asked if i needed to run the analysis again via sonar.
And in that context, I’ll say that your primary motivation to get your JaCoCo report passed into analysis would be to have all your code quality data (and history/trends!) in one place.
Yes that is why im asking how to get the coverage into Sonar.
i did try looking at some property in Team city that would be set but couldnt find any
Hi Ann,
So i got passed setting the jacoco.exec property.Now im left with two issues in the build.log which im hoping you can help me resolve
In the teamcity build log…
The following classes needed for analysis were missing:
No information about coverage per test (my guess is if i solve 1. then 2 will go away)
NOTE: in the SonarCubeRunner i have specified the property below in “Additional Parameters”
-Dsonar.java.binaries=relative path to test classes folder
Also one general question:(this is just for my understand of how sonarcube does its analysis so pardon my ignorance)
When jacoco produces the coverage file ie jacoco.exec,im assuming it hgas all the code coverage info inside it like branch/line coverage etc.When this jacoco.exec file is used by sonarcube does sonarcube do
1.displays the information in the file
2. does it own anaylsis(ie does code coverage again?) and then displays the result
3.does something else?
sonar.java.binaries should point to the compiled .class files of your main source code. If you want to also provide the compiled classes of your test code (which is a good thing to do) then you’ll use the sonar.java.test.binaries (docs here. Fixing that should handle the warning about classes needed for analysis.
Your second issue is completely separate, and in fact, we don’t handle that data any more.
For your final question about how the JaCoCo report is used, the answer is 1 and some 2. Specifically, for files that are omitted from the coverage report, analysis calculates how many executable (and therefore coverable) lines are in the file, and adds that to the denominator when overall coverage percentage is calculated. This is why you may be seeing different overall coverage reported by SonarQube vs JaCoCo.
HTH,
Ann
P.S. For additional questions, please open new threads.