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
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);
}
}
}