Is it possible to change the content of a snapshot created by a build result during the build?
Hi,
I have a customer who is trying to change the content of snapshot created by a Build result.
The use case is that we have N component in the stream and we create some jar,war and ear packages with those components. But only 3 of those components will contain a package(ear,war,etc...). So we like to take a snapshot of those 3 components at the end the build and attach it to the actual Build Result. So whenever somebody open the build result, he/she will see only the components that have a dowloadable package.
Or which way would it be better to implement such a case? We thought about removing the uncessary components from BuildUser's workspace by using scm command in build.xml so the snapshot will only contain our desired component but didnt work.
Is it possible to do this kind of operations or not? I believe RTC wouldn't allow us to manipulate that snapshot.
2 answers
As Nick commented:
but there's currently no way of associating an arbitrary snapshot with the build result in the same way as the original snapshot
We wrote an Ant task that allows one to associate a snapshot to a build result. The task works, but once we started using the task we started experiencing this temporarily missing snapshot problem. EDIT: The issue has been resolved and the code below was updated to correct the issue. In certain cases, we associate the same snapshot to more than one build result (e.g. rebuild scenarios). The first time we associate the snapshot to the build result, all works fine. But, subsequent attempts sometimes fail where the server tells us that the item is no longer available. After some time, later attempts for the same item will work. Perhaps our Ant task is putting the snapshot into a temporary bad state?
The body of the Ant task is:
IBaselineSet snapshot = getSnapshot(this.snapshotUUID, getTeamRepository(), getProgressMonitor());
addSnapshotContributionToBuild(snapshot, getBuildResult(
IBuildResult.PROPERTIES_COMPLETE), getTeamRepository(), getProgressMonitor());
The body of the Ant task uses these two methods:
private IBaselineSet getSnapshot(String snapshotUuid, ITeamRepository teamRepository, IProgressMonitor progressMonitor)
throws TeamRepositoryException {IBaselineSetHandle baselineSetHandle = (IBaselineSetHandle)
IBaselineSet.ITEM_TYPE.createItemHandle(UUID.valueOf(snapshotUuid), null);return (IBaselineSet) teamRepository.itemManager().fetchCompleteItem(
baselineSetHandle, IItemManager.REFRESH, progressMonitor);
}
public void addSnapshotContributionToBuild(IBaselineSet snapshot,
IBuildResult buildResult, ITeamRepository teamRepository,
IProgressMonitor progressMonitor)
throws TeamRepositoryException {IBuildResultContribution contribution =
BuildItemFactory.createBuildResultContribution();contribution.setExtendedContributionTypeId(
ScmConstants.EXTENDED_DATA_TYPE_ID_BUILD_SNAPSHOT);
contribution.setImpactsPrimaryResult(false);
contribution.setLabel(NLS.bind(
AntMessages.TeamAcceptTask_SNAPSHOT_CONTRIBUTION_LABEL,
snapshot.getName()));
contribution.setExtendedContribution(snapshot);ITeamBuildClient buildClient = ClientFactory.getTeamBuildClient(teamRepository);
buildClient.addBuildResultContribution(buildResult, contribution,
progressMonitor);
}
Comments
Hi Nick,
Thanks for the answer. linkpublisher is a good method. I am not that familiar with SCM command line but I know that we can give a name to the snapshot while creating it. So we have a name for the custom snapshot but I was wondering how we can get the UUID of this custom snapshot in ant so we can use linkpublisher.
Thanks in advance
You would need to specify -u y on the command line to have it generate UUIDs in the output, then parse that out, set it as an environment variable, and then bring that in to Ant using the property Ant task. I realize this involves a lot of duct tape and baling wire, unfortunately. Since 4.0, the SCM CLI supports JSON output as well. For an intro to the SCM CLI and how to use it for this kind of scripting, see https://jazz.net/library/article/1031
Hi Nick,
Hi Rachel, the situation hasn't changed. The only recourse for now is to use the SCM CLI to create a new snapshot, and publish a link to it as a regular link contribution, as suggested above.