It's all about the answers!

Ask a question

Retrieving build history using Java API


Albin Joseph (403610) | asked Nov 06 '12, 10:46 a.m.
edited Nov 07 '12, 10:39 a.m. by Ralph Schoon (63.1k33645)
Hi,

Is it possible to retrieve the build history using Java API?

Actually what I am trying to do is to find the name of the snapshots created by the last two builds. So I think the first step to do that is to retrieve the build history.

Thanks
-Albin

4 answers



permanent link
Lauren Hayward Schaefer (3.3k11727) | answered Nov 14 '12, 7:46 a.m.
JAZZ DEVELOPER
edited Nov 14 '12, 7:48 a.m.
Hi Albin,
Somehow I missed the notification from your last comment.  Sorry for the delay!  I think you may want to try "buildResultQueryModel.buildDefinition()._eq(query.newItemHandleArg())" instead of " buildResultQueryModel._eq(buildDefinition.getItemHandle()" .  I'm including the code from a method I have that queries for an individual build based on its label and build definition in case it helps you:

IBuildResultQueryModel buildResultQueryModel = IBuildResultQueryModel.ROOT;
IItemQuery query = IItemQuery.FACTORY.newInstance(buildResultQueryModel);
query.filter( query.and(buildResultQueryModel.label()._like(query.newStringArg()), buildResultQueryModel.buildDefinition()._eq(query.newItemHandleArg())));
query.orderByDsc(buildResultQueryModel.buildStartTime());
IProgressMonitor monitor = new NullProgressMonitor();
ITeamBuildClient buildClient = (ITeamBuildClient) teamRepository.getClientLibrary(ITeamBuildClient.class);
IBuildDefinition buildDefinition = buildClient.getBuildDefinition(buildDefinitionId, monitor);
Object[] parameters = new Object[] { label, buildDefinition };
IItemQueryPage queryPage = buildClient.queryItems(query, parameters, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, monitor);
if (queryPage.getSize() == 1) {
    return (IBuildResult) teamRepository.itemManager().fetchCompleteItems(queryPage.getItemHandles(), IItemManager.DEFAULT, monitor).get(0);
}
else {
    return null;
}

permanent link
Ralph Schoon (63.1k33645) | answered Nov 07 '12, 10:42 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You might want to look into this article where I get the builds https://jazz.net/library/article/807. Maybe there is something new you can reuse.

What is the issue you are seeing with your expression?

Comments
Ralph Schoon commented Nov 07 '12, 10:47 a.m. | edited Nov 07 '12, 10:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

And you might want to look at this post too, because that could be what you want: http://ryehle.wordpress.com/2012/06/28/custom-build-result-pruner/


permanent link
Albin Joseph (403610) | answered Nov 07 '12, 10:00 a.m.
edited Nov 07 '12, 10:01 a.m.
 Hi Lauren,

Thank you for your reply. I had a look into that code and I have created some code by following the examples. However it did not work for me. The code that I have today is given below.

TeamPlatform.startup();
IProgressMonitor monitor = new NullProgressMonitor();
ITeamRepository teamRepository = login("https://localhost:9443/jazz/", "user", "password", monitor);
ITeamBuildClient buildClient = (ITeamBuildClient) teamRepository .getClientLibrary(ITeamBuildClient.class);
IBuildDefinition buildDefinition = buildClient.getBuildDefinition("RTC_Deploy", monitor);
IBuildResultQueryModel buildResultQueryModel = IBuildResultQueryModel.ROOT;
IItemQuery query = IItemQuery.FACTORY.newInstance(buildResultQueryModel);
query.filter(buildResultQueryModel._eq(buildDefinition.getItemHandle()));
query.orderByDsc(buildResultQueryModel.buildStartTime());
String[] parameters = new String[] { };
IItemQueryPage queryPage = buildClient.queryItems(query, parameters, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, monitor);
System.out.println(queryPage.getItemHandles());

What I am doing wrong with the above code?

Thanks
-Albin

Comments
Lauren Hayward Schaefer commented Nov 07 '12, 10:29 a.m.
JAZZ DEVELOPER

Hi Albin,
Can you explain how it did not work for you?


Albin Joseph commented Nov 08 '12, 9:54 a.m. | edited Nov 08 '12, 9:57 a.m.

Its not retrieving any information. The list is empty.  I think there is something wrong with my query or filter. 


permanent link
Lauren Hayward Schaefer (3.3k11727) | answered Nov 07 '12, 7:44 a.m.
JAZZ DEVELOPER
Hi Albin,
I'm not sure offhand how much information you can get about a build using the Java API.  https://jazz.net/wiki/bin/view/Main/BuildJavaProgrammingExamples has examples of how to query for builds, which may help you get started.

Your answer


Register or to post your answer.