Getting build statistics over REST API while build is in progress

I am in need to control execution of later steps based on values of statistics from former steps. E.g. I want to do some further actions when there is more failed tests than certain threshold. I tried to solve this by 'curling' TC REST API and getting number of failed tests from there (http....statistics/FailedTestCount). This works fine when I am asking this value after the build is completed, but when this command is part of build step, I get error response stating 'No statistics data for key: PassedTestCount'.

I am curious, is there some delay before I can ask this test statistic, or is it getting published after build finishes? I can see number of passed tests when given build step finishes (progress message of build changes to 'Tests passed: N').

Footnote: Is there some other way to get these statistics into build step script?

Comment actions Permalink

Due to implementation details, it becomes available for REST API after build is finished.

Comment actions Permalink

OK, good to know.

In the mean time, I already resolved it with 3 lines of grep/sed/awk code. For those that might need it, to get number of executed tests:

TESTS=$(cat ${TESTSUITE_FILE} | grep "<testsuite .*>" | sed -r "s/(<.* )(tests=\")([[:digit:]]+)(.*>)/\3/" | tr ' ' '\n' | gawk '{ sum+=$1 } END{ print sum}')

Explained: take testsuite, find testsuite elements, find test attribute and take its value, separate those matches by newline and let awk to sum it up
To get other attributes, change 'tests'.


Please sign in to leave a comment.