From looking at the TeamCity REST API Documentation, the request for statistical data is:
http://teamcity:8111/httpAuth/app/rest/builds/<buildLocator>/statistics/
Which works, however, it only gives statistics for the current build (tests passed, code coverage, number of duplicates, etc.), I am looking to build a graph for my build radiator showing trends, therefore I want the historical data for the past month.
Is there a way to get this historical statistic data from the TeamCity API?
Rather than hit the DB directly, you can get at the data via the exportchart endpoint on TeamCity. This is not a documented API (at least to my knowledge) but I found that altering the "type" query string param to json gives you json data (rather than the default CSV). You can learn more about this endpoint by messing around with the drop-downs on the Build Configuration -> Statistics tab and then checking out the URL used for the "Download data as CSV" download icon/button.
e.g.
http://teamcity/exportchart.html?type=json&buildTypeId=bt2&%40f_range=MONTH&%40filter.status=WARNING&showBranches=true&_graphKey=g&valueType=CodeCoverage&id=CodeCoveragebt2
From what I can tell, there are no custom date ranges allowed.
(note that "bt2" is a build configuration id from my system)
To get statistics values for a set of builds, since TeamCity 8.1 use the request as in the TeamCity REST doc:
http://teamcity:8111/app/rest/builds?locator=BUILDS_LOCATOR&fields=build(id,number,status,buildType(id,name,projectName),statistics(property(name,value)))
This basically returns build nodes matching BUILDS_LOCATOR and "expands" statistics in each. e.g. use "buildType:(id:BUILD_CONFIG_ID)" as "BUILDS_LOCATOR" to get the builds form the build configuration with the UI-configured id "BUILD_CONFIG_ID".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With