Getting build result linked to a work item
Thanks.
Sola
Accepted answer
/**
* Link between a build and a work item to indicate that the work item was
* reported against the build.
*/
public static final String REPORTED_WORK_ITEMS = "com.ibm.team.build.linktype.reportedWorkItems"; //$NON-NLS-1$
/**
* Link between a build and a work item to indicate that the changes
* associated with the work item are included in the build.
*/
public static final String INCLUDED_WORK_ITEMS = "com.ibm.team.build.linktype.includedWorkItems"; //$NON-NLS-1$
These are item links, so the source reference is a build result item handle, and the target reference is a work item handle.
To create the link, use ILinkServiceLibrary methods, e.g. something like:
ILinkServiceLibrary linkService = getLinkServiceLibrary();
IBuildResultHandle buildResultHandle = ...;
IWorkItemHandle workItemHandle = ...;
IItemReference buildResultRef = linkService.referenceFactory().createReferenceToItem(buildResultHandle);
IItemReference workItemRef = linkService.referenceFactory().createReferenceToItem(workItemHandle);
ILink link = linkService.createLink("com.ibm.team.build.linktype.reportedWorkItems", buildResultRef, workItemRef);
linkService.saveLink(link);
where getLinkServiceLibrary() is:
private ILinkServiceLibrary getLinkServiceLibrary() {
return (ILinkServiceLibrary) getService(ILinkService.class).getServiceLibrary(ILinkServiceLibrary.class);
}
3 other answers
The build-related link types are defined by the Build component. The Work Items component doesn't know about them. Constants for them are defined in com.ibm.team.build.internal.common.links.BuildLinkTypes, i.e./**
* Link between a build and a work item to indicate that the work item was
* reported against the build.
*/
public static final String REPORTED_WORK_ITEMS = "com.ibm.team.build.linktype.reportedWorkItems"; //$NON-NLS-1$
/**
* Link between a build and a work item to indicate that the changes
* associated with the work item are included in the build.
*/
public static final String INCLUDED_WORK_ITEMS = "com.ibm.team.build.linktype.includedWorkItems"; //$NON-NLS-1$
These are item links, so the source reference is a build result item handle, and the target reference is a work item handle.
To create the link, use ILinkServiceLibrary methods, e.g. something like:
ILinkServiceLibrary linkService = getLinkServiceLibrary();
IBuildResultHandle buildResultHandle = ...;
IWorkItemHandle workItemHandle = ...;
IItemReference buildResultRef = linkService.referenceFactory().createReferenceToItem(buildResultHandle);
IItemReference workItemRef = linkService.referenceFactory().createReferenceToItem(workItemHandle);
ILink link = linkService.createLink("com.ibm.team.build.linktype.reportedWorkItems", buildResultRef, workItemRef);
linkService.saveLink(link);
where getLinkServiceLibrary() is:
private ILinkServiceLibrary getLinkServiceLibrary() {
return (ILinkServiceLibrary) getService(ILinkService.class).getServiceLibrary(ILinkServiceLibrary.class);
}
Hi,
Do you know how we can do the same from a snippet because we don't see ILinkServiceLibrary on the plain libraries client size.
Thanks
For example, Build's (internal) WorkItemHelper class uses these as follows:
public static IWorkItemHandle[] getLinkedWorkItems(ITeamRepository teamRepository,
IBuildResultHandle buildResultHandle, String buildLinkType, IProgressMonitor monitor)
throws TeamRepositoryException {
ValidationHelper.validateNotNull("teamRepository", teamRepository); //$NON-NLS-1$
ValidationHelper.validateNotNull("buildResultHandle", buildResultHandle); //$NON-NLS-1$
ValidationHelper.validateNotNull("buildLinkType", buildLinkType); //$NON-NLS-1$
List<IWorkItemHandle> reportedWorkItems = new ArrayList<IWorkItemHandle>();
ILinkManager linkManager = (ILinkManager) teamRepository.getClientLibrary(ILinkManager.class);
IReference source = linkManager.referenceFactory().createReferenceToItem(buildResultHandle);
ILinkCollection referencesToResults = linkManager.findLinksBySource(buildLinkType, source,
monitor).getAllLinksFromHereOn();
for (Object object : referencesToResults) {
ILink link = (ILink) object;
IWorkItemHandle workItemHandle = (IWorkItemHandle) link.getTargetRef().resolve();
if (workItemHandle != null) {
reportedWorkItems.add(workItemHandle);
}
}
return (IWorkItemHandle[]) reportedWorkItems.toArray(new IWorkItemHandle[reportedWorkItems.size()]);
}
Comments
Hello
What If I have the Build Result Link and I need to add this in the work item, same asĀ linking above?
https://<Server>.com:9443/ccm/web/projects/MY_BUILD_PROJECT#action=com.ibm.team.build.viewResult&id=_AXxKISh6EeKIIeAdAaNGgA
I want to add a normal reference to the work item for this build result.
Praveen, you should probably describe the context you are asking better. For example,are you developing a client or server extension.
Some hints can be found here:
http://rsjazz.wordpress.com/2012/10/20/following-calm-links-using-the-java-client-or-server-api/
http://rsjazz.wordpress.com/2012/09/20/the-rtc-workitem-server-link-api-linking-to-work-items-and-other-elements/
http://rsjazz.wordpress.com/2012/09/19/the-rtc-workitem-link-api-linking-workitems-to-other-elements/
I think you should be able to use the described approaches to analyze how build results are linked to the work items today and create them that way.