It's all about the answers!

Ask a question

Programatically modify build result


Karthik Krishnan (8594100149) | asked Jan 26 '12, 4:57 a.m.
Hi,

Is it possible to modify build result via Plain JAVA API?

I am looking to add Files to build result nightly. Is this possible?

Thanks

Karthik

5 answers



permanent link
Nick Edgar (6.5k711) | answered Jan 26 '12, 11:03 a.m.
JAZZ DEVELOPER
Yes, from the client side you can use:
com.ibm.team.build.client.ITeamBuildClient.addBuildResultContribution(IBuildResultHandle, IBuildResultContribution, IProgressMonitor)
where the client interface is obtained using:
com.ibm.team.build.client.ClientFactory.getTeamBuildClient(ITeamRepository)

Upload the IContent content blob first, then set it as the contribution's data:
com.ibm.team.build.common.model.IBuildResultContribution.setExtendedContributionData(IContent)

Other properties like the file name and size can be set as properties on the contribution.

The contribution object can be created using:
com.ibm.team.build.common.BuildItemFactory.createBuildResultContribution()

For details, I suggest looking at the source for the artifactFilePublisher and logPublisher Ant tasks:
com.ibm.team.build.ant.task.ArtifactFilePublisherTask
com.ibm.team.build.ant.task.LogPublisherTask

In particular, they both go through:
com.ibm.team.build.internal.publishing.AbstractFilePublisher.initializeContribution(IBuildResultContribution, ITeamRepository)
com.ibm.team.build.internal.publishing.ContentPublisher.getFileContent(ITeamRepository)
com.ibm.team.build.internal.publishing.ContentPublisher.storeTextContent(String, File, ITeamRepository)

permanent link
SEC Servizi (97122652) | answered Jan 27 '12, 6:09 a.m.
Hi Nick,
we have a file we want to add to build results from the client side.
1. We create the Java instance for the file:
File file = new File("C:/foo.txt");

2. We store a IContent with this File:
ITeamRepository teamRepository = (ITeamRepository) repo.getClientLibrary(ITeamRepository.class);

IContent content = (IContent) teamRepository.contentManager().storeContent(new FileInputStream(file), null);

3. We create a IBuildResultContribution and set its data with the IContent:
IBuildResultContribution contribution = BuildItemFactory.createBuildResultContribution(); 

contribution.setLabel(label);
contribution.setComponentName(componentName);
contribution.setExtendedContributionData(content);

4. We add the contribution to a IBuildResult:
buildClient.addBuildResultContribution(buildResult, contribution, null);

The steps seem correct to us, but the method storeContent(InputStream, IPorgressMonitor) is depreceted. Neither we can find the storeTextContent(String, File, ITeamRepository) method you mention from a IContentManager instance.
We have to use the internal classes?
Any help will be appreciated.

Cheers.

permanent link
Karthik Krishnan (8594100149) | answered Jan 30 '12, 9:39 a.m.
Thank you nick, will explore the possibilities

permanent link
SEC Servizi (97122652) | answered Feb 03 '12, 11:10 a.m.
the method storeContent(InputStream, IPorgressMonitor) is depreceted.

The correct method to store a IContent seems to be:
IContent content = teamRepository.contentManager().storeContent(IContent.CONTENT_TYPE_UNKNOWN, null, LineDelimiter.LINE_DELIMITER_NONE, new FileInputStream(file), null, null);

We found it in another post from Nick: https://jazz.net/forums/viewtopic.php?p=64327#64327 :wink:

permanent link
Nick Edgar (6.5k711) | answered Feb 03 '12, 11:38 a.m.
JAZZ DEVELOPER
Sorry, I missed your Jan 27 comment.

Your answer


Register or to post your answer.