buildStatisticValue service message - do not work

As the last part of a build I print out a service message (impl class of BuildProcess)
     String tstStats = String.format("##teamcity[buildStatisticValue key='%s' value='%d']", "foobar", 4711);
  System.out.printf(tstStats);

On the server I have created a results tab for a build
  class MyResultsTab extends ViewLogTab {}
and in the fillModel method I try to retrieve it using
void fillModel(Map<String, Object> model, HttpServletRequest r, SBuild build) {
  BigDecimal foobar = build.getStatisticValue("foobar");
  model.put("foobar", foobar != null ? foobar.intValue() : "42");
  debug.print("model: %s", model);

However, the stats value 'foobar' do not appear in my console debug printout.

What is the proper way -step by step- to pass a few key-value pairs from the agent build to the server-side and present it at a tab?

5 comments
Comment actions Permalink

Hi Jens,

You can check if the statistics value was published for a build, for example with REST API: http://server.url/app/rest/builds/id:BUILD_ID/statistics
Where you can get BUILD_ID from the build results page URL.

If the value is listed - the issue is with the retrieving part. If not - with the publishing one.

> What is the proper way -step by step- to pass a few key-value pairs from  the agent build to the server-side and present it at a tab?

What you describe should work. Statistics values are OK if you plan to draw a chart for the values over time or be able to fail a build based on the value. Othervise, you can pass the values as parameters or just publish build artifact which is then processed on the server side.

0
Comment actions Permalink

I just tried the rest api (per your suggestion) and the 'foobar' variable is not part of it.

Got back the following xml from
URL: http://localhost:8111/app/rest/builds/id:10/statistics
<properties>

<property name="ArtifactsSize" value="5236"/>

<property name="BuildDuration" value="149600"/>

<property name="BuildDurationNetTime" value="149600"/>

<property name="buildStageDuration:artifactsPublishing" value="505"/>

<property name="buildStageDuration:buildFinishing" value="79"/>

<property name="buildStageDuration:buildStepRUNNER_3" value="143292"/>

<property name="buildStageDuration:firstStepPreparation" value="1422"/>

<property name="BuildTestStatus" value="1"/>

<property name="SuccessRate" value="1"/>

<property name="TimeSpentInQueue" value="1086"/>

</properties>

These values are the same I get back from the debug printouts
build.statisticValues: {
    buildStageDuration:firstStepPreparation=1422,
    buildStageDuration:buildFinishing=79,
    buildStageDuration:buildStepRUNNER_3=143292,
    TimeSpentInQueue=1086,
    BuildTestStatus=1,
    SuccessRate=1,
    buildStageDuration:artifactsPublishing=505,
    BuildDuration=149600,
    ArtifactsSize=5236,
    BuildDurationNetTime=149600
}


So, where to go now?

I'm developing a plugin for a customer. The plugin is running a load-test as a build-step. After a successful run, it should show a small table in a tab, with data such as responseTime/throughput/errors and url to the full report.

How to I pass some data (eg key=value pairs) from the agent back to the server? I would really appreciate step-by-step instructions.

0
Comment actions Permalink

I added some service messages using operation message.

The following lines are executed from within the agent BuildProcess.
System.out.println("##teamcity[message text='Starting up the load-test']");
//. . .
System.out.println("##teamcity[message text='Completed the load-test']");
System.out.printf("##teamcity[buildStatisticValue key='%s' value='%d']%n", "foobar", 4711);
System.out.printf("##teamcity[buildStatisticValue key='%s' value='%d']%n", "responseTime", 8500);
System.out.printf("##teamcity[buildStatisticValue key='%s' value='%d']%n", "throughput", 1000);
System.out.printf("##teamcity[buildStatisticValue key='%s' value='%d']%n", "errors", 15);

The 'message' parts are printed in the agent console window, but not the buildStatisticValue parts. Have also tried without line-endings, but with the same result.

This is the text from the documentation:
In order to be processed by TeamCity they should be printed into standard output stream of the build (otherwise, if the output is not in the service message syntax, it should appear in the build log). A single service message should not contain a newline character inside it, it should not span across multiple lines.

Do you mean something different than 'System.out' when you say 'standard output stream'?

0
Comment actions Permalink

Hi Jens,

> Do you mean something different than 'System.out' when you say 'standard output stream'?

No. System.out.println should work. Please print a separate message per line.
Could you run the same code not from TeamCity and check the output?

I'd also try a simple approach to use a comamnd line runner in TeamCity with a script like:
echo "##teamcity[buildStatisticValue key='MyTestValue1' value='2']"
and check the results.

BTW, what TeamCity version do you use?


As to other ways to pass a value from a build: you can use other service messages to publish a value as parameter or upload a file as build artifact and then use those on the server side.


BTW, do you have any plans to make the plugin public?

0
Comment actions Permalink

>>what TeamCity version do you use?
8.0.5 @ Ubuntu 13.10

>> use other service messages to publish a value
haven't seen any service message working as advertized

>>upload a file as build artifact
that became my solution to the problem

>>any plans to make the plugin public?
my customer will release it to the public in Q1/14

0

Please sign in to leave a comment.