It's all about the answers!

Ask a question

Retrieving the build ID


Paul Klicnik (2633) | asked Nov 17 '09, 12:15 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
Is there a way to get the ID/Name of the build definition associated with a IBuildResult?

Seems like I can get a IBuildDefinitionHandle using the following approach:
IBuildDefinitionHandle handle = buildResult.getBuildDefinition()

but the IBuildDefinitionHandle API doesn't provide a simple getName() (or similar) API

Any suggestions?

6 answers



permanent link
Nick Edgar (6.5k711) | answered Nov 18 '09, 6:09 a.m.
JAZZ DEVELOPER
Generally in Jazz, when an item refers to another it does so via a handle. The handle is somewhat like a URI in that it identifies the item, but is not the item itself. The item needs to be fetched using the item service.

The API for fetching items differs depending on whether you're doing this client-side or server-side. For client-side, use the fetch methods on IItemManager. For server side, use the fetch methods on IRepositoryItemService.

Also, note that there are two possible answers for the definition id for a build. Do you want the current id, or the id at the time of the request?

The IBuildRequest for the build result (IBuildResult.getBuildRequests()) captures the state of the build definition at the time of the request in its IBuildDefinitionInstance (IBuildRequest.getBuildDefinitionInstance()). So if you want the current id for the build definition, fetch the definition then use IBuildDefinition.getId(). If you want the id at the time of the request, fetch the request then use IBuildRequest.getBuildDefinitionInstance() and IBuildDefinitionInstance.getBuildDefinitionId().

Note that IBuildDefinitionInstance is a 'helper' not a separate item, so it's contained within the IBuildRequest, and doesn't require a separate fetch.

permanent link
Paul Klicnik (2633) | answered Nov 18 '09, 9:59 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
If you want the id at the time of the request, fetch the request then use IBuildRequest.getBuildDefinitionInstance() and IBuildDefinitionInstance.getBuildDefinitionId().


Getting the ID at the time of build request would be ideal .

I should have mentioned that I'm on RTC2.0. I just checked and it appears the IBuildRequest.getBuildDefinitionInstance() API is not available. Is this API available in RTC2.0?

permanent link
Nick Edgar (6.5k711) | answered Nov 18 '09, 12:16 p.m.
JAZZ DEVELOPER
IBuildRequest.getBuildDefinitionInstance() is there since 1.0. Note that it's on IBuildRequest, not IBuildResult.

permanent link
alex hutter (1111) | answered May 12 '10, 1:06 p.m.
JAZZ DEVELOPER
I have tried this:

List<?> buildRequests = buildResult.getBuildRequests();

however it seems that getBuildRequests() returns BuildRequestHandle, not IBuildRequest.

BuildRequestHandle buildRequest = (BuildRequestHandle) buildRequests.get(0);

Any suggestions? A complete example on how to go from IBuildResult to the name of the build definition would be really helpful.

thanks!

permanent link
Nick Edgar (6.5k711) | answered May 12 '10, 5:48 p.m.
JAZZ DEVELOPER
If using the client side API, try:

ITeamRepository repository = ...;
IBuildResult result = ...;
IBuildRequestHandle requestHandle = null;
if (!result.getBuildRequests().isEmpty()) {
requestHandle = (IBuildRequestHandle) result.getBuildRequests().get(0);
}
IBuildRequest request = (IBuildRequest) repository.itemManager().fetchCompleteItem(requestHandle, IItemManager.DEFAULT, null);
String definitionId = request.getBuildDefinitionInstance().getBuildDefinitionId();


You shouldn't need to refer to internals to do this. Using the item manager is the usual way to fetch items (i.e. convert from an item handle to an item). You can also fetch partial items, which can be faster, e.g. if you only need some properties of the item(s). See the other methods on IItemManager.

It's also recommended to do proper progress monitoring for good user feedback (I passed null for the progress monitor above).

Should also handle the case where requestHandle is null. This can happen if the request somehow gets deleted without the result having been deleted, which shouldn't happen in normal usage, but the code should still be resilient.

permanent link
alex hutter (1111) | answered May 13 '10, 6:16 a.m.
JAZZ DEVELOPER
thanks very much, that really helped!

Your answer


Register or to post your answer.