It's all about the answers!

Ask a question

Obtaining all Build Results from Build Definition


Eric Harmon (61) | asked Sep 12 '09, 4:08 a.m.
I've been trying two different ways to get all the build results for a build definition.

First method:

I currently have code that will iterate through the repository and return every single build definition. Is there a way to access all the build results from these build definitions?

Second method:

I followed the example on https://jazz.net/wiki/bin/view/Main/BuildJavaProgrammingExamples, and currently am able to get all the build results from the respository, sorted by their build times. Unfortunately, this means that the build results can be from any of the build definitions.

I've tried to do:
IBuildResult buildResult = (IBuildResult) result;
IBuildDefinitionHandle buildDefinition = buildResult.getBuildDefinition();

I have tested the buildResult and it contains the data. However, this IBuildDefinitionHandle that is returned is null. I've checked it using the debugger as well as trying:

UUID buildId= buildDefinition.getItemId();
System.out.println(buildId.toString());


Essentially what I'm trying to do is to compile a list of all the build definitions with their respective build results. If I'm able to iterate through each build definition for the build results that's great. Otherwise, just grabbing every build result and then sorting them myself based on build definition will work as well.

Thanks.

2 answers



permanent link
Nick Edgar (6.5k711) | answered Sep 13 '09, 4:15 p.m.
JAZZ DEVELOPER
Hi Eric,

To query the build results for a given build definition, add a filter to the query like:

query.filter(buildResultQueryModel.buildDefinition()._eq(query.newItemHandleArg()));

Then when you run the query, pass the build definition handle:

Object[] parameters = new Object[] { buildDefinitionHandle };
IItemQueryPage queryPage = buildClient.queryItems(query, parameters, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE,
monitor);


For the 2nd issue, of getting null back for the build definition, that's happening because the example specifies that only the label property be fetched for the resulting items. Try changing the properties passed to fetchPartialItems to:

String[] properties = new String[] { IBuildResult.PROPERTY_LABEL, IBuildResult.PROPERTY_BUILD_DEFINITION };


Though you won't need to fetch the definition property if you change the query to filter by definition. I suggest querying by definition rather than getting all results then grouping by definition, as the query for all results may be very large, and the longer you take to process a query, the greater the risk that the cached query results gets flushed from the server (this is only an issue if the query results span multiple pages).

The example also skips an important aspect: you need to page over the results if there's more than one page. In the call to queryItems, it specifies the maximum allowable page size, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, which is 512. If there are more than these many results, there will be multiple pages. You can check if you need to iterate using:

...
IQueryPage queryPage = buildClient.queryItems(query, parameters, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, monitor);
while (true) {
// do your thing with the results in queryPage,
// then fetch next page if there is one
if (queryPage.hasNext()) {
queryPage = queryService.fetchPage(queryPage.getToken(), queryPage.getNextStartPosition(), queryPage.getSize(), monitor);
} else {
// if not, break out of the loop
break;
}


Regards,
Nick Edgar
RTC Build component lead

permanent link
Eric Harmon (61) | answered Sep 13 '09, 8:34 p.m.
Hi Nick,

Thanks for putting the time in making your response. I haven't gotten a chance yet to implement this, but I know you've saved me a lot of time and frustration!

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.