How to update the artifact URL in build results programatically?
We store the RTC build output in network File share. Unfortunately the exiting url works only in Internet Explorer as the link always has file:// .
I want to update the exiting buildResultContribution links from file:// to file:///// to make it work across all clients.
I am writing a Java application to do this and while doing so, when I use the below code it adds a new entry instead of updating the existing.
// newURL contains the changed url pattern - file:// to file://///
buildResultContribution.setExtendedContributionProperty(IBuildResultContribution.PROPERTY_NAME_URL, newURL);
buildClient.addBuildResultContribution((IBuildResultHandle)buildResultWorkingCopy.getItemHandle() , buildResultContribution, null);
buildClient.save(buildResultWorkingCopy, null);
How can I save an existing instead of creating new?
2 answers
Some of that API is explained in https://rsjazz.wordpress.com/2015/10/28/build-artifacts-publishing-and-automated-build-output-management-using-the-plain-java-client-libraries/ and the linked articles. From the example build output manager:
String theURL = publishToIRAM(aBuildOutputCandidate); IBuildResultContribution link = BuildItemFactory .createBuildResultContribution(); // Optional set a category // link.setComponentName("Build Output Backup for Audits"); link.setLabel("Download Artifact from Asset Manager"); link .setExtendedContributionTypeId(IBuildResultContribution.LINK_EXTENDED_CONTRIBUTION_ID); link.setExtendedContributionProperty( IBuildResultContribution.PROPERTY_NAME_URL, theURL); ITeamBuildClient buildClient = (ITeamBuildClient) aTeamRepository .getClientLibrary(ITeamBuildClient.class); buildClient.addBuildResultContribution((IBuildResultHandle) buildResult .getItemHandle(), link, null);
Comments
Thanks Ralph for the update. I read the blog and the source code.
I found no way to update the existing Artifact link. The code which I posted adds a new entry.
I downloaded the SDK now. I will look for some pointers there.
You are correct, I think that is contributing a new link and not updating it. Have you considered to find the contribution and then the link in it and change that? Just a thought.
I've added my comment as answer as it crosses the limit.
I am actually doing that. Below is the piece of my code. I am trying to update in the context of the current BuildResultContribution.
IBuildResultContribution[] buildResultContributionArr = buildClient.getBuildResultContributions( buildResultWorkingCopy, new String[] { IBuildResultContribution.ARTIFACT_EXTENDED_CONTRIBUTION_ID},
rtcManager.getProgressMonitor());
for (IBuildResultContribution brArtifactLink : buildResultContributionArr) { String fileURL = brArtifactLink.getExtendedContributionProperty(IBuildResultContribution.PROPERTY_NAME_URL); String newURL=""; if (fileURL!=null) { if(fileURL.contains("file://")) { newURL=fileURL.replaceAll("file://", "file://///"); //brArtifactLink.setExtendedContributionTypeId(brArtifactLink.getExtendedContributionTypeId()); brArtifactLink.setExtendedContributionProperty(fileURL, newURL); //brArtifactLink.setExtendedContributionData buildClient.addBuildResultContribution((IBuildResultHandle)buildResultWorkingCopy.getItemHandle() , brArtifactLink, null); //buildClient.save(buildResultWorkingCopy, null); } }}