Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BTSKTask AddResource - How to raise an error in case the command fails

We are using the following command to deploy BizTalk assemblies via PowerShell:

BTSTask AddResource /ApplicationName:$App /Type:$BizTalkAssemblyType /Overwrite /Source:$Source /Options:GacOnAdd,GacOnInstall,GacOnImport

See: https://learn.microsoft.com/en-us/biztalk/core/addresource-command-biztalk-assembly

There are certain reasons this command can fail, e.g. an orchestration is not in the unenlisted state or one or more instances of the orchestration exists.

In this case the command does not raise an error so the script continues with an output like

Command failed with 1 errors, 0 warnings.

Because in this situation the assembly does not get deployed we would like to fail the PowerShell script e.g. by raising an error. How to achieve this?

like image 792
Chris Avatar asked Nov 15 '22 17:11

Chris


1 Answers

You need to capture the output and check it for the failure, or rather, check for success and fail if it doesn't.

[array] $cmdOutput = BTSTask AddResource /ApplicationName:$App /Type:$BizTalkAssemblyType /Overwrite /Source:$Source /Options:"GacOnAdd,GacOnInstall,GacOnImport"

$line = $cmdOutput.Count-2


if ( $cmdOutput[$line] -eq "Command succeeded with 0 errors, 0 warnings.")
{
    Write-Output "Deploy suceeded"
}
else
{
    Throw "Deploy failed $cmdOutput" 
}
like image 103
Dijkgraaf Avatar answered Jan 12 '23 01:01

Dijkgraaf