Thursday, March 7, 2013

Integrating Code-quality Reports to Teamcity

How do we display the code-quality reports like PMD, Findbugs, Checkstyle in Teamcity?
I wasted a lot of time to find this out. I guess it's a common problem, hence posting the steps.
Option 1:
Generate your quality reports in html format.

Configure the report (eg: FindbugReport.html) as an artifact in Teamcity

Administration -> Project -> Build Configuration -> Edit Configuration Settings -> 1. General Settings -> Artifact paths



Add report file path with the name. It should be relative to the Build Checkout Directory.

After the next build, report is seen as an artifact and you can click on it to view the report.

Option 2:
You can also display the report as a project tab.
But if you have several build configurations under the project, this can be misleading since you define the tab to display a report corresponding to a single configuration even-though the tab appear commonly to all configurations as a project tab. If you have only one configuration in project it should be fine.

Follow the steps in option 1.

Administration -> Project -> Report Tabs -> Create new report tab




You can simply give the report name (not the path) here since you have defined it as an artifact.

Report will be displayed under a new tab with the tab name you defined.
If the artifact is not available it will not be seen.


Option 3:
Use the Teamcity code inspection feature. Teamcity generates a report by combining the xml quality reports.

Generate your quality reports in xml format.

Administration -> Project -> Build Configuration -> Edit Configuration Settings -> 3. Build Step: Ant -> Additional Build Features -> Add Build feature


Select "XML report processing" from the drop down

Select report type, PMD, findbugs etc

In Monitoring rules add the file path (the same way you add the artifact path, relative to the Build Checkout Directory.)


Done!
You can see a single Code Inspection report as seen below. But here you cannot have a format you want like in option 1 and also it doesn't say which ones are findbugs issues and which are PMD.
Build results summarize the inspections total.
And a tab and a link as shown below.

Report is displayed like this

2 comments:

  1. Hi Kal,
    I read your post, and looking for something like this (checkstyle + teamcity). I have some questions:
    The output is only html report with code inspections? when report shows fail then teamcity build will also fail? Or build will pass but code inspection will show the code mistakes on red color?
    Status of build is the most important for me :)

    ReplyDelete
  2. Hi Kal,
    I have implemented my setup for generating pmd,checkstyle report as option 3 that you have described.
    my report are succussfully parsed but code inspection tab is not visible in WebUI.

    ReplyDelete