How to get Associated Release with a build result using java api
5 answers
you have to go the other way... the IDeliverable object represents the release, and the Artifact attribute of that object points to the associated IBuildResult.
I haven't done it, but I assume you can use the Query model to search for IDeliverable objects and maybe filter on Artifact = specific BuildResult.
see one of my query samples
https://jazz.net/forum/questions/150094/determining-build-definitions-associated-with-a-specific-project-area
search for "answered May 04 '14, 5:25 p.m. " in that topic
I haven't done it, but I assume you can use the Query model to search for IDeliverable objects and maybe filter on Artifact = specific BuildResult.
see one of my query samples
https://jazz.net/forum/questions/150094/determining-build-definitions-associated-with-a-specific-project-area
search for "answered May 04 '14, 5:25 p.m. " in that topic
see the first answer here
https://jazz.net/forum/questions/14122/enumerating-through-releases-defined-in-a-project-area
https://jazz.net/forum/questions/14122/enumerating-through-releases-defined-in-a-project-area
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;
}
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;
}