Retrieving Statistical History from TeamCity API

From a look at the TeamCity REST API Documentation, a request for statistics:

http://teamcity:8111/httpAuth/app/rest/builds/<buildLocator>/statistics/ 

What works, however, it only gives statistics for the current assembly (tests passed, code coverage, number of duplicates, etc.), I am looking to build a graph for my assembly radiator showing trends, so I want historical data for the last month.

Is there any way to get these historical statistics from the TeamCity API?

+5
source share
3 answers

Unfortunately, I could not get this data exclusively from the TeamCity API, so the solution should go against the database.

 select build_data_storage.build_id, build_type_mapping.ext_id as 'build_type_id', data_storage_dict.value_type_key as 'metric_name', build_data_storage.metric_value, history.build_number, history.build_finish_time_server from build_data_storage join data_storage_dict on build_data_storage.metric_id = data_storage_dict.metric_id join history on build_data_storage.build_id = history.build_id join build_type_mapping on history.build_type_id = build_type_mapping.int_id 
-1
source

Instead of directly accessing the database, you can get data through the exportchart TeamCity endpoint. This is not a documented API (at least as far as I know), but I found that changing the request parameter of type “type” for json gives you json data (not the default CSV). You can learn more about this endpoint by messing around with the drop-down lists on the “Assembly Configuration →” tab and then checking the URL used for the “Download data as CSV” download icon.

eg.

HTTP: //teamcity/exportchart.html type = JSON & buildTypeId = BT2 &% 40f_range = MONTH &% 40filter.status = ATTENTION & showBranches = true & _graphKey = g & ValueType? = & amp code coverage; ID = CodeCoveragebt2

From what I can say, there are no valid date ranges.

(note that "bt2" is the build configuration identifier from my system)

+1
source

Get statistics for a set of builds, because TeamCity 8.1 uses the query, as in the TeamCity REST Document :

  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 the assembly nodes corresponding to BUILDS_LOCATOR and "expanding" the statistics in each. for example, use "buildType: (id: BUILD_CONFIG_ID)" as "BUILDS_LOCATOR" to get assemblies from the assembly configuration with the UI-configured identifier "BUILD_CONFIG_ID".

0
source

Source: https://habr.com/ru/post/1201079/


All Articles