Consider following scripted pipeline:
Contents of the test.ps1 is following:
The script is specifically designed to fail on trying to access undefined variable. This scenario is working correctly, Jenkins detects that PowerShell script returned something other than 0 exit code and fails pipeline execution.
However! If the script to be changed this way (only line 1 has changed):
Then the script fails exactly the same way, but Jenkins fails to detect this failure and proceeds to execute stage 2.
Invoking both versions of the PowerShell script manually shows that in both cases powershell process exit code is 1. I fail to understand how adding parameter attribute to PowerShell script affects Jenkins ability to detect script outcome.