It's all about the answers!

Ask a question

How to get Associated Release with a build result using java api if I have the build result


K M (38325051) | asked Apr 06 '15, 12:51 p.m.
I can use workitem client to query all deliverables in a project then
loop to find the one I want

 Is their no client and model that can be used so I can query and filter like I do for build results?
ie
ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
IBuildResultQueryModel buildResultQueryModel = IBuildResultQueryModel.ROOT;

One answer



permanent link
K M (38325051) | answered Apr 06 '15, 1:24 p.m.
once you have the build result, you can do the following

    public IBuildResult queryForBuildUsingLastModifiedTime(Timestamp lastModified) throws TeamRepositoryException {       
        ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
        IBuildResultQueryModel buildResultQueryModel = IBuildResultQueryModel.ROOT;
        IItemQuery query = IItemQuery.FACTORY.newInstance(buildResultQueryModel);
        IBuildResult result = null;
       
        // Create query filter, Last Modified and tags not eq ""
        query.filter(buildResultQueryModel.modified()._gtOrEq(query.newDateTimeArg())._and(buildResultQueryModel.tags()._notEq(query.newStringArg())));
        query.orderByDsc(buildResultQueryModel.buildStartTime());
        Object[] parameters = new Object[] { lastModified,"" };
       
        // Run query and return results
        IItemQueryPage queryPage = buildClient.queryItems(query,parameters, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, MONITOR);
       
        int i = 0;
        while (i < queryPage.getSize()) {           
            IWorkItemClient workItemClient = ((IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class));
            IBuildResult tmp_result = (IBuildResult) repo.itemManager().fetchCompleteItems(queryPage.getItemHandles(), IItemManager.DEFAULT, MONITOR).get(i);

            // Create profile
            ItemProfile<IDeliverable> profile = ItemProfile.<IDeliverable> createProfile(IDeliverable.ITEM_TYPE,
                    AuditablesHelper.AUDITABLE_SMALL_PROFILE).createExtension(
                    Arrays.asList(new String[] {IDeliverable.NAME_PROPERTY, IDeliverable.DESCRIPTION_PROPERTY,
                            IDeliverable.PROJECT_AREA_PROPERTY}));

           
            //IDeliverable
            List<IDeliverable> deliverables = workItemClient.findDeliverablesByArtifact(tmp_result, profile,MONITOR);
            for (int x = 0; x < deliverables.size(); x++) {
                System.out.println("deliverable: " + deliverables.get(x).getName());
                System.out.println("deliverable: " + deliverables.get(x).getItemId().getUuidValue());
            }
           
            System.out.println("label: " + tmp_result.getLabel());
            System.out.println("last modified: " + tmp_result.modified().toString()  );
            System.out.println("start time: " + Long.toString(tmp_result.getBuildStartTime()));
            System.out.println("tags: " + tmp_result.getTags());
            System.out.println("uuid: " + tmp_result.getItemId().getUuidValue());
            i++;
        }
        return result;
    }


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.