PowerShell Doesn’t Fail Jenkins Job

When dealing with automation on Windows platform, PowerShell comes in very handy and there is no doubt about it. Things can be automated quite easily with it.

However, you want the Jenkins job in which PowerShell is used to fail if your PowerShell script fails. I have had cases where I saw my script crapped out but the job itself succeeded.

To solve the problem, all you have to do is to add the following line at the beginning of the PowerShell script step.

$ErrorActionPreference = "Stop"

This will “successfully fail” your Jenkins job if your script throws any exception.

Author: admin

A software engineer in greater Seattle area

Leave a Reply

Your email address will not be published. Required fields are marked *