Filter test history by branch in REST API

Completed

I would like to retrieve the most recent 50 test occurrences of a test by name and build type where those occurrences were on a specified branch.

I don't see a way to accomplish, but am hoping someone can help me out.

In this example I get the 50 most recent for the build type and test name, but from all branches.

/guestAuth/app/rest/testOccurrences/?locator=test:(name:my_test_name),buildType:(id:Core_Configs_Vc110x64),count:50&fields=testOccurrence(id,name,status,href,details,duration,build(buildTypeId,number,branchName))

If I try to filter on build, I get a single result

/guestAuth/app/rest/testOccurrences/?locator=test:(name:my_test_name),buildType:(id:Core_Configs_Vc110x64),build:(branch:(name:master))),count:50&fields=testOccurrence(id,name,status,href,details,duration,build(buildTypeId,number,branchName))

Applying the branch selector to the test parses, but produces no different result from the first.  It returns testOcurrences from multiple branches.

/guestAuth/app/rest/testOccurrences/?locator=test:(name:my_test_name,build:(branch:(name:master))),buildType:(id:Core_Configs_Vc110x64),count:50&fields=testOccurrence(id,name,status,href,details,duration,build(buildTypeId,number,branchName))

Any suggestions on how to formulate the query?

 

Thanks,

Rob

0
8 comments

I think the branch needs to be added to the locator as you've attempted, but I think maybe you've added it incorrectly. Try this:

/guestAuth/app/rest/testOccurrences/?locator=test:(name:my_test_name),build(buildType:Core_Configs_Vc110x64,branch:master),count:50&fields=testOccurrence(id,name,status,href,details,duration,build(buildTypeId,number,branchName))

 

0

Sorry, but that returns a result set with the same problem as my first and 3rd queries.   It includes responses from branches other than `master`.

0

What release of TeamCity are you using?

0

TeamCity Enterprise 2019.2.2 (build 71923)

0

I am not sure why you're getting other branches in your results if your locator includes "build(buildType:Core_Configs_Vc110x64,branch:master)". Are you able to use the locator on a branch in a simpler query? Try something like this with different branch names in place of <branch name>:

/guestAuth/app/rest/testOccurrences/?locator=build(buildType:Core_Configs_Vc110x64,branch:<branch name>),count:50&fields=testOccurrence(build(branchName))

 

0

Yes, the query you supplied that omits the test locator returns results only from the requested branch.

0

Since that request results in only the desired branch, add only the test portion to the locator like below. Do you still only get the requested branch?

/guestAuth/app/rest/testOccurrences/?locator=test(name:<test name>),build(buildType:Core_Configs_Vc110x64,branch:<branch name>),count:50&fields=testOccurrence(build(branchName))
0

Thanks.  I will try this the next time I'm in that code. 

0

Please sign in to leave a comment.