It's all about the answers!

Ask a question

How to get previous buildResults


Moti Wertheimer (18913628) | asked Jun 13 '13, 5:12 a.m.
JAZZ DEVELOPER
edited Jun 13 '13, 11:24 a.m. by Ralph Schoon (63.7k33648)
Hi,
Using Java client I can get IBuildResult instance using the Query model.
Now I want to get the build before this build.
I see a way to do it using IBuildResultStatusTrend::getPreviousBuilds
But I have no access to this class using the Client (If I am not wrong).

Is there a way to get the previous builds out of a given build?

Comments
Ralph Schoon commented Jun 13 '13, 11:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Not sure if that will help, but I think you should be able to get the build definition and thenĀ  all the build results for it. I would try that.


Moti Wertheimer commented Jun 16 '13, 9:37 a.m. | edited Jun 16 '13, 9:38 a.m.
JAZZ DEVELOPER

Thanks Ralph,

But I cannot see how get the buildResults out of the buildDefinition.
The association is only from BuildResult to BuildDefinition and not the opposite
build data model from the SDK

Accepted answer


permanent link
Lauren Hayward Schaefer (3.3k11727) | answered Jun 17 '13, 6:45 a.m.
JAZZ DEVELOPER
edited Jun 17 '13, 6:47 a.m.
Regarding Moti's comment above about getting the build results out of the build definition:  It is possible to get the build results from the build definition.  I'm including a method below that queries for a specific build using a label and build definition, but you could pull out the code related to the label:

    public IBuildResult queryForBuildUsingLabelAndBuildDefinition(String label, String buildDefinitionId, ITeamRepository teamRepository) throws TeamRepositoryException {        
        IBuildResultQueryModel buildResultQueryModel = IBuildResultQueryModel.ROOT;
        IItemQuery query = IItemQuery.FACTORY.newInstance(buildResultQueryModel);         query.filter( query.and(buildResultQueryModel.label()._like(query.newStringArg()), buildResultQueryModel.buildDefinition()._eq(query.newItemHandleArg())));
        query.orderByDsc(buildResultQueryModel.buildStartTime());
        IProgressMonitor monitor = new NullProgressMonitor();
        ITeamBuildClient buildClient = (ITeamBuildClient) teamRepository.getClientLibrary(ITeamBuildClient.class);
        IBuildDefinition buildDefinition = buildClient.getBuildDefinition(buildDefinitionId, monitor);
        Object[] parameters = new Object[] { label, buildDefinition };   
        IItemQueryPage queryPage = buildClient.queryItems(query, parameters, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, monitor);         if (queryPage.getSize() == 1) {             return (IBuildResult) teamRepository.itemManager().fetchCompleteItems(queryPage.getItemHandles(), IItemManager.DEFAULT, monitor).get(0);
        }
        else {
            return null;
        }
    }
Moti Wertheimer selected this answer as the correct answer

Comments
Moti Wertheimer commented Jun 18 '13, 6:09 a.m.
JAZZ DEVELOPER
I used it to get the list of all builds in dsc order, iterating it lets me find the previous build.

Thanks,
Moti

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.