Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Getting build result linked to a work item

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

0 votes


Accepted answer

Permanent link
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

1 vote

Comments

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
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

0 votes


Permanent link
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()]);
}

0 votes

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.


Permanent link
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.

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Sep 06 '11, 11:00 a.m.

Question was seen: 8,309 times

Last updated: Jul 17 '13, 11:28 a.m.

Confirmation Cancel Confirm