Vasyl Stepulo
Vasyl Stepulo

Reputation: 1603

Fail Jenkins build if condition occured in Powershell script

I have a code, which checks free space on disk, and if space is not enought - stops and fails build:

$freespace = Get-PSDrive D

$DiskDSpace = ($freespace.Free) 

If ($DiskDSpace -lt 214748364809999999999) { 
echo "Free space on disk D is less than 20 GB" 
exit 1 
exit $LastExitCode 
}

But it only skip all other actions in current Powershell script and continues to execute build. My question is how to fail jenkins build inside PS script, when condition not met?

Upvotes: 2

Views: 2780

Answers (1)

TurboToast
TurboToast

Reputation: 78

You're not setting the $LastExitCode to anything.

Change:

exit 1 
exit $LastExitCode 

To:

$LastExitCode = 1
exit $LastExitCode 

Upvotes: 2

Related Questions