It's all about the answers!

Ask a question

Getting build result linked to a work item


Sola Otudeko (4511316) | asked Sep 06 '11, 11:00 a.m.
Hi, I am writing a RTC server-side plugin (operation participant) and would like to get the build result record linked to a work item ie. Using the "Reported against Build" link on the work item. This particular link is not defined in both WorkItemTypes.java or WorkItemEndPoints.java (in com\ibm\team\workitem\common\model). Any one know how I can do this? I can't find anything that may also list all links (from which I can look for the one I need).
Thanks.
Sola

Accepted answer


permanent link
Nick Edgar (6.5k711) | answered Sep 08 '11, 9:26 p.m.
JAZZ DEVELOPER
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);
}
Ralph Schoon selected this answer as the correct answer

Comments
Morten Madsen commented Jun 09 '13, 12:26 p.m.

Hi, I just used this code using the Java client API (used the ILinkManager instead of ILinkServiceLibrary).

The work item gets a nice link "Included in builds" but my build result does not show the work item.

Any ideas why this happens?

3 other answers



permanent link
Luis Bazo (6832019) | answered Sep 21 '11, 11:07 a.m.
JAZZ DEVELOPER
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

permanent link
Nick Edgar (6.5k711) | answered Sep 21 '11, 12:16 p.m.
JAZZ DEVELOPER
The corresponding client-side methods are all on com.ibm.team.links.client.ILinkManager, which you can get as a client library from the ITeamRepository connection.

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
praveen patidar commented Nov 06 '12, 9:08 p.m.

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.


Ralph Schoon commented Nov 07 '12, 2:50 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


permanent link
Nick Edgar (6.5k711) | answered Jul 17 '13, 11:27 a.m.
JAZZ DEVELOPER
edited Jul 17 '13, 11:28 a.m.
For more on contributing "included in build" links to a build (via client-side API), see thread https://jazz.net/forum/questions/117259/adding-work-items-to-build-result-using-api

It involves more than just creating the links.

Your answer


Register or to post your answer.