2

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?

Vasyl Stepulo
  • 1,493
  • 1
  • 23
  • 43

1 Answers1

2

You're not setting the $LastExitCode to anything.

Change:

exit 1 
exit $LastExitCode 

To:

$LastExitCode = 1
exit $LastExitCode 
TurboToast
  • 78
  • 5