I have a Hudson server with a few Jobs. One job creates a package another one deploys the package. Creating and deploying the package is based on a MSBuild file. This file calls some powershell scripts. In one of the scripts there is a valid error like below. Unfortunatly my MSBuild script doesn't pick it up as an error and continues the rest of the script, which also complete fails of course.
C:\Hudson\TRUNK\buildfiles\deploy\PowershellScripts\ExtractPackages.ps1 : Cannot bind argument to parameter 'Packages'
because it is an empty string.At line:1 char:249
+ ... nt\ONT\Package ''
C:\Hudson\TRUNK\buildfiles ...
+ ~~
+ CategoryInfo : InvalidData: (:) [ExtractPackages.ps1], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,ExtractPackages.ps1
My MSBuild target looks like:
<Target Name="UnpackProducts">
<Exec Command="$(PowerShellExe) -command "&{ $(PowershellScriptsFolder)\ExtractPackages.ps1 '@(Packages)' ; exit $lastexitcode }"" />
</Target>
I always thought that the ; exit $lastexitcode
solved this issue. But it doesn't, or am I doing something wrong?
For now I've added <Error Condition="@(Packages) == ''" Text="Packages are missing!"/>
before calling the actual powershell command to check this specific case. But I'd like to know how to fail the build via powershell with any given error.
Please, try to escape special character (Dollar Sign $), and, probably, ' sign in your command:
<Target Name="UnpackProducts">
<Exec Command="$(PowerShellExe) -command "&{ $(PowershellScriptsFolder)\ExtractPackages.ps1 %27@(Packages)%27 ; exit %24lastexitcode }"" />
</Target>
Probably that is your mistake.