How do you deliver the snapshot created by a build to the stream?
We are using EE dependency builds which do not have the post-build option to deliver the snapshot.
I wrote an ant task that uses the api to do the deliver, but nothing happens -- no errors, no messages, no delivery. With the CLI you have to add -o option to make it work. Do I need something special using the API to duplicate the -o option?
This will make the CLI do the delivery:
<!-- ScmDeliverSnapshot Macro --> <macrodef name="ScmDeliverSnapshot">But, I can't use this with EE or JBE on zOS. CLI doesn't like the parms, must be backleveled.
<attribute name="property" default="scm.property.output.ScmDeliverSnapshot"/>
<attribute name="workspace"/>
<attribute name="stream"/>
<sequential>
<local name="scm.cmd"/>
<Scm property="scm.cmd"/>
<local name="scm.property.output.ScmDeliverSnapshot"/>
<exec executable="${scm.cmd}" failonerror="true" outputproperty="@{property}">
<arg value="--config"/>
<arg value="${dir.scc}"/>
<arg value="--non-interactive"/>
<arg value="deliver"/>
<arg value="-o"/>
<arg value="-v"/>
<arg value="-s"/>
<arg value="@{workspace}"/>
<arg value="-t"/>
<arg value="@{stream}"/>
</exec>
<ac:propertycopy name="scmTemp" from="@{property}" override="true"/>
<echo level="verbose">Scm: @{property}:</echo>
<echo level="verbose">${scmTemp}</echo>
</sequential>
</macrodef>
Here's the deliver code which does not deliver:
// Search for stream IWorkspaceSearchCriteria criteria = IWorkspaceSearchCriteria.FACTORY.newInstance().setKind(IWorkspaceSearchCriteria.STREAMS);
criteria.setExactName(getStreamName());
List<IWorkspaceHandle> streamWorkspaceHandles = wsManager.findWorkspaces(criteria,Integer.MAX_VALUE,null);
// Verify one stream
if (streamWorkspaceHandles.size() == 0) {
throw new TeamRepositoryException(NLS.bind(CommonMessages.COMMON_NOTFOUND_STREAMNAME,getStreamName()));
}
// Connect to stream
IWorkspaceHandle streamWorkspaceHandle = streamWorkspaceHandles.get(0);
IWorkspace streamWorkspace = (IWorkspace) repo.itemManager().fetchCompleteItem(streamWorkspaceHandle,IItemManager.DEFAULT,null);
IWorkspaceConnection streamWorkspaceConnection = wsManager.getWorkspaceConnection(streamWorkspace,null);
// Get change report
syncReport = wsConnection.compareTo(streamWorkspaceConnection,WorkspaceComparisonFlags.INCLUDE_BASELINE_INFO,Collections.EMPTY_LIST,null);
// Deliver to stream
for (Object changeHandle : syncReport.outgoingChangeSets()) {
// Check IChangeSetHandle
if (!(changeHandle instanceof IChangeSetHandle)) {continue;}
// Get change set details
IChangeSet changeSet = scmChangeset.getSnapshotChangeset((IChangeSetHandle) changeHandle);
IComponentHandle componentHandle = changeSet.getComponent();
// Deliver pending change
wsConnection.deliver(streamWorkspaceConnection,syncReport,syncReport.outgoingBaselines(componentHandle),syncReport.outgoingChangeSets(componentHandle),null);
}
The syncReport.outgoingBaselines() = 3 before and after code executes. Completes without any message saying why deliver failed.
Accepted answer
I got this to work using a JBE on zos unix system by changing macro to use <ant line=...> format:
<!-- ScmDeliverSnapshot Macro -->
<macrodef name="ScmDeliverSnapshot">
<attribute name="failonerror" default="true"/>
<attribute name="property" default="scm.property.output.ScmDeliverSnapshot"/>
<attribute name="workspace"/>
<attribute name="stream"/>
<sequential>
<local name="scm.cmd"/>
<Scm property="scm.cmd"/>
<local name="scm.property.output.ScmDeliverSnapshot"/>
<exec executable="${scm.cmd}" failonerror="@{failonerror}" outputproperty="@{property}" osfamily="windows">
<arg value="--config"/>
<arg value="${dir.scc}"/>
<arg value="--non-interactive"/>
<arg value="deliver"/>
<arg value="-o"/>
<arg value="-v"/>
<arg value="-s"/>
<arg value="@{workspace}"/>
<arg value="-t"/>
<arg value="@{stream}"/>
</exec>
<exec executable="${scm.cmd}" failonerror="@{failonerror}" outputproperty="@{property}" os="z/OS">
<arg line="--config ${dir.scc} --non-interactive deliver -o -v -s @{workspace} -t @{stream}"/>
</exec>
<local name="scm.tmp"/>
<ac:propertycopy name="scm.tmp" from="@{property}" override="true" silent="true"/>
<local name="current.time"/>
<tstamp>
<format property="current.time" pattern="yyyyMMdd HH:mm:ss.SSS"/>
</tstamp>
<echo level="verbose">${current.time} Scm: @{property}:</echo>
<echo level="verbose">${scm.tmp}</echo>
</sequential>
</macrodef>
Macro is now setup to handle windows systems and zos.
Still would like to know how to get API to handle situations like this though.
djr
Comments
3 other answers
- streamWorkspaceHandles.size() == 0 is risky, because you may have multiple IWorkspaces with the same name. I suggest verifying that you have exactly one workspace that fits the criteria. An even better alternative would be to hard-code the UUID of the IWorkspace you want to deliver to (you could parameterize it if you want to reuse the code).
- The loop that does the delivery loops over each change set, so it will attempt to perform multiple deliveries of the same change sets and baselines. You can get a list of components with IChangeHistorySyncReport#localComponents() .
Comments
IChangeHistorySyncReport changeHistorySyncReport = sourceFlowNodeConnection.compareTo(
targetFlowNodeConnection,
WorkspaceComparisonFlags.INCLUDE_BASELINE_INFO | WorkspaceComparisonFlags.INCLUDE_EMPTY_BASELINES,
Collections.EMPTY_LIST, /*excludedComponents*/
progressMonitor);
List<IComponentHandle> componentHandles = changeHistorySyncReport.localComponents();
//FOR EVERY COMPONENT (note that some components may not be mapped in the target workspace)
for(IComponentHandle componentHandle : componentHandles) {
//IMPORTANT from API desc: The order of the baselines in the result reflects the
//order in which they were bases in the local history,
// in reverse chronological order.
List<IBaselineHandle> outgoingBaselineHandles =
changeHistorySyncReport.outgoingBaselines(componentHandle);
//IMPORTANT from API desc: The order of the change sets in the result reflects their
// relative order in the local history
for that component.
List<IChangeSetHandle> outgoingChangeSetAfterBasisHandles =
changeHistorySyncReport.outgoingChangeSetsAfterBasis(componentHandle);
//DELIVER ONLY POSSIBILE LATEST BASELINE FOR COMPONENT AND CHANGESETS ON TOP
if (outgoingBaselineHandles.size() > 0) {
try {
sourceWorkspaceConnection.deliver(
targetWorkspaceConnection,
changeHistorySyncReport,
Collections.singletonList(outgoingBaselineHandles.get(0)),
outgoingChangeSetAfterBasisHandles,
progressMonitor);
} catch (TeamRepositoryException e) {
log.error("FAILED delivery last baseline and change sets",e);
throw new SnipException("FAILED delivery last baseline and change sets",e);
}
} else {
try {
sourceWorkspaceConnection.deliver(
targetWorkspaceConnection,
changeHistorySyncReport,
Collections.EMPTY_LIST,
outgoingChangeSetAfterBasisHandles,
progressMonitor);
} catch (TeamRepositoryException e) {
log.error("FAILED delivery change sets only",e);
throw new SnipException("FAILED delivery change sets only",e);
}
}
}