Powershell Script returning status code
search cancel

Powershell Script returning status code

book

Article ID: 207164

calendar_today

Updated On:

Products

CA Release Automation - Release Operations Center (Nolio)

Issue/Introduction

When running an action PowerShell run script block it is always passing and not returning the status code in case of exception.

Environment

Release : 6.6

Component : CA RELEASE AUTOMATION RELEASE OPERATIONS CENTER

Cause

The Script execution by the action PowerShell Run Script block rely on your script/script block to return the status code conditionally or in case of any exception. In case of no explicit exception is returned the PowerShell script exit with $LASTEXITCODE, which in case of Non-Terminating errors will be 0.

Resolution

The example script on how the powershell script should handle returning conditional status code is as below.

$dest="c:\DirDoesNotExist"
$status
try{
cd $dest -ErrorAction Stop
}
catch [System.Exception]{
"Exception Occurred"
$status=1
}
finally{
exit $status
}

Additional Information

For more detail around PowerShell script refer PowerShell official documents