我有一个代码,它检查磁盘上的可用空间,如果空间不足 - 停止并失败构建:
$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
}
但它只是跳过当前 Powershell 脚本中的所有其他操作并继续执行构建。 我的问题是,当条件不满足时,如何在 PS 脚本内构建 jenkins 失败?
最佳答案
您没有将 $LastExitCode 设置为任何内容。
更改:
exit 1
exit $LastExitCode
致:
$LastExitCode = 1
exit $LastExitCode
关于powershell - 如果 Powershell 脚本中出现条件,则 Jenkins 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53324907/