It's all about the answers!

Ask a question

How to update the artifact URL in build results programatically?


Karthik Krishnan (859498146) | asked Apr 05 '17, 11:21 a.m.
edited Apr 05 '17, 11:23 a.m.

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



permanent link
Ralph Schoon (59.7k23643) | answered Apr 06 '17, 2:49 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 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
Karthik Krishnan commented Apr 06 '17, 10:28 a.m.

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.


Ralph Schoon commented Apr 06 '17, 10:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


Karthik Krishnan commented Apr 06 '17, 10:58 a.m.

I've added my comment as answer as it crosses the limit.


permanent link
Karthik Krishnan (859498146) | answered Apr 06 '17, 10:58 a.m.
edited Apr 06 '17, 10:59 a.m.

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

Your answer


Register or to post your answer.