Detecting when the BAM update-All Command fails

Topics: General Questions, Server Deployment, Tips and Tricks
Apr 14, 2011 at 6:32 PM

hi All,

is it possible to detect and catch the failure of the following command via Windows scripting ?:

bm.exe update-all -DefinitionFile:"H:\Projects\BAMGM.xml

my idea is when this command fails, perform a undeploy and then a full deploy, tha aim of this is to reduce the losing of BAM data due changes in the definition.

Any other suggestion or idea is welcome!

thanks

Julian R Berlin

Coordinator
Apr 14, 2011 at 7:09 PM

Hi Julian,

I believe bm.exe sets a non-zero error code when it has an error, which you can pick up through the .NET process API or scripting tools.  During a deployment, I believe the BTDF script will fail and stop if bm.exe fails on the update-all step.  Are you planning to run this separately before the deployment script?

Thanks,
Tom

Apr 15, 2011 at 1:36 PM

Hi Tom,

I am planning to run all together in the same file, do think it is possible to modify the archive .Targets to detect the failure of the Update-all?

thanks again !

Julian

Coordinator
Apr 15, 2011 at 2:11 PM

Hi Julian,

I'm not sure which file you're referring to - archive .targets?  If you mean the new file that you're creating, then by default the Exec task that you'd use to call bm.exe will stop the script if bm.exe sets an error code.  (If you want it to continue without breaking, you'd have to add the ContinueOnError="true" attribute.)  I'm not certain if bm.exe sets an error code when an update-all fails, but I am fairly sure that it does.

Thanks,
Tom

Apr 18, 2011 at 2:10 PM

Hi Tom,

thanks a lot for the reply, do you know how to detect this failure from the script ? the invocation of the bm.exe returns a non zero value if it fails ?

Thanks !

Julian

Coordinator
Apr 18, 2011 at 2:42 PM

Yes, you can capture the bm.exe exit error code into an MSBuild property and then test it against zero.  Here's a blog post that demonstrates the idea.

Thanks,
Tom

Apr 18, 2011 at 2:43 PM

I checked the BiztalkDeploymentFramework.Targets .file

I want to add a similar line as follows to execute the undeploy and deploy of the BAM definition if the Update-All command fails:

<Message Text="Deploying BAM tracking profiles..." Condition="'@(BamTrackingProfilesQualified)' != ''" />
    <Exec
      Command="&quot;$(BtsDir)Tracking\BttDeploy.exe&quot; &quot;@(BamTrackingProfilesQualified)&quot;"
      Condition="'%(Identity)' == '%(Identity)' and '@(BamTrackingProfilesQualified)' != ''" />
    <Message Text="Finished deploying BAM tracking profiles." Condition="'@(BamTrackingProfilesQualified)' != ''" />

it is possible to store to declare a variable, store a value in it and later use it in another command or in a condition as below ?

thank you in advance,

Julian

Coordinator
Apr 18, 2011 at 3:28 PM

Hi Julian,

I'd suggest looking up the MSBuild reference on MSDN for general MSBuild scripting questions, but yes, you can create a property and refer to it later.  $(BtsDir) is a property reference.  @(BamTrackingProfilesQualified) is an item group reference.

If the existing BAM undeploy and deploy behavior is OK, then you could just ask the Deployment Framework to do just that step.  Ideally you would just call MSBuild using the MSBuild task (MSBuild calling another instance of itself) and pass it your .btdfproj file path, the target name DeployBam and the property value SkipBamUndeploy=false.  However, there's one catch.  A couple of properties (BtsDir and DeployTools) would be undefined because the GetSoftwarePaths target is not listed in the DependsOnTargets attribute on DeployBam.

That leaves you a couple of options.  You can copy and paste parts from the BTDF .targets and assemble exactly what you want, as you were starting to do.  Or, you can replicate the entire DeployBam target into your .btdfproj and modify DependsOnTargets to include GetSoftwarePaths (plus the existing values).  In effect you are overriding the default implementation.  That way (I think) if you directly run DeployBam through the MSBuild command-line (or MSBuild task) it should work OK.

(It's hard to explain all of this since you are probably not familiar with MSBuild, so half of that probably doesn't make any sense...)

Thanks,
Tom