I am using below script to connect to remote server and shut the cluster service and then deploy packages. This is cluster service shut down script.
$SvcName = '${bamboo.ServiceName}'
$SvrNames = '${bamboo.deploy.hostname}'
#$SvcName = "'" + $SvcName + "'"
$SvrName = $SvrNames[0]
try {
$services = Get-WmiObject -Computer $SvrName -Authentication PacketPrivacy -Namespace 'root\mscluster' MSCluster_Resource |
Where {$_.Type -eq "Generic Service"} |
Where {$_.name -eq $SvcName}
if (-Not $Services) {
$SvcName + " is not installed on this computer."
} else {
Switch($services.state) {
'2' {
Write-Host "Cluster service $SvcName is online"
$SvcName = "'" + $SvcName + "'"
$cmd = "CLUSTER RES" + ' ' + $SvcName + ' ' + "/OFF"
$cmd1 = [scriptblock]::Create($cmd)
Invoke-Command -ComputerName $SvrName -ScriptBlock $cmd1
Start-Sleep -s 10
Write-Host "$SvcName is Offline"
}
'3' {
Write-Host "Cluster service $SvcName is Offline"
Write-Host $_.Exception
Write-Host $_.Exception.Message
Start-Sleep -s 10
break
}
'4'{
Write-Host "Cluster service $SvcName is in Falied state, Please login to $SvrNames and check event logs"
Start-Sleep -s 10
}
}
}
} catch {
$error[0].Exception
Write-Host $_.Exception
Write-Host $_.Exception.Message
break
}
Why does Bamboo does not fail when there is a clear exception or an error message in the deploy logs?
Do I need to do something different here?
$LASTEXITCODE
doesn't work as well.
I've found another work around.
Most of the errors in PowerShell throws exceptions. For and unknown reason, Bamboo doesn't seem to take that into account when executing inline scripts.
We can fix that by doing our own exception catching inline, like:
With that, I was able to have the deployment properly failed. The inline check for $error[0] stated above also works but maybe not will all exceptions.