How to retrieve Service Message data from REST API

Completed

Hi All,

 

Our build system augments test results using Service Messages (https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html) including a "testFailed" message type message that is displayed in the UI.  

Can anyone let me know where I can find that data via REST API?   I don't see it under app/rest/builds/<locator>/statistics, app/rest/builds/<locator>/artifacts/metadata, app/rest/builds/<locator>/artifacts/chidlren, or under app/rest/testOccurrences/<locator>

 

Thanks,

Rob

7 comments
Comment actions Permalink

Hi Rob,

What aspects of the tests are you looking to retrieve? You can use `/app/rest/builds?locator=id:<build id>&fields=build(statusText)` to get the same overview as the UI. You can also retrieve the individual details of the tests from `/app/rest/testOccurrences?locator=build(id:<build id>)&fields=testOccurrence(details)`.

Does this help get you closer to what you're looking?

Thanks,

Eric

0
Comment actions Permalink

Hi Eric,

 

If my build script emits the following:

##teamcity[testFailed timestamp='00:00:00.000' name='MyTestName' message='1 / 3 cases failed']

Where will that be accessible via REST API?

I have not found it under builds or testOccurrences, but I might not have tried the correct endpoint.

 

Thanks,

Rob

0
Comment actions Permalink

Normally, you'd find it with `/app/rest/testOccurrences?locator=build(id:<build id>)&fields=testOccurrence(details)`.

However, I don't think your example service message meets the requirements of the test Failed service message, so it is likely not being recognized by TeamCity as a failed result and not showing up with your Rest API request. It is my understanding that the service message for testFailed must follow one of two formats:

As seen in the Test result section of the documentation on Supported Test Service Messages:

##teamcity[testFailed name='MyTest.test1' message='failure message' details='message and stack trace']

or

##teamcity[testFailed type='comparisonFailure' name='MyTest.test2' message='failure message' details='message and stack trace' expected='expected value' actual='actual value']

Indicates that the testname test failed. Only one testFailed message can appear for a given test name.

  • message contains the textual representation of the error.

  • details contains detailed information on the test failure, typically a message and an exception stacktrace.

  • actual and expected attributes can only be used together with type='comparisonFailure' to report comparison failure. The values will be used when opening the test in the IDE.

Here is another example with the Rest API response:

echo ##teamcity[testSuiteStarted name='suiteName']
echo ##teamcity[testStarted name='testName' captureStandardOutput='true']
echo ##teamcity[testFinished name='testName']
echo ##teamcity[testStarted name='testName2' captureStandardOutput='true']
echo ##teamcity[testFailed name='testName2' message='1 / 3 cases failed' details='This is the details section of the build script message']
echo ##teamcity[testFinished name='testName2']
echo ##teamcity[testSuiteFinished name='suiteName']

Using `/app/rest/testOccurrences?locator=build(id:<build id>)&fields=testOccurrence(name,status,details)`, I receive the following:

<testOccurrences>
<testOccurrence name="suiteName: testName" status="SUCCESS">
<details/>
</testOccurrence>
<testOccurrence name="suiteName: testName2" status="FAILURE">
<details>
1 / 3 cases failed This is the details section of the build script message
</details>
</testOccurrence>
0
Comment actions Permalink

Thanks.  I'll look into that.

0
Comment actions Permalink

Eric just after quick review, these messages cause testOccurence status to report correctly.  Are you saying that the message is recorded as part of details and only if details is also provided?   Why bother with two parameters then?

0
Comment actions Permalink

Hi Robert,

I am mistaken, you can use the timestamp parameter in this service message. However, you should still be able to retrieve the message contents in the details field with `/app/rest/testOccurrences?locator=build(id:<build id>)&fields=testOccurrence(details)`. Do you have anything showing up with this request?

You could also try using `/app/rest/testOccurrences?locator=build(id:<build id>)&fields=testOccurrence($long)` to receive all of the fields.

Thanks,

Eric

1
Comment actions Permalink

Hi Eric,

That did it.   <details> wasn't in the default set of fields returned.   I see my message at the very end of the details string.

Thanks,
Rob

 

0

Please sign in to leave a comment.