我将此作为脚本的一部分
$timeoutSeconds = $timeoutMinutes * 60
$job = Start-Job -ScriptBlock $block -ArgumentList @($environment, $filter)
Wait-Job $job -Timeout $timeoutSeconds
Stop-Job $job
Remove-Job $job
如果超时,我想提出错误(是章鱼部署步骤的一部分)
由于
答案 0 :(得分:4)
这样的事情怎么样:
Wait-Job $job -Timeout $timeoutSeconds
if ($job.state -eq 'Running') {
Write-Error "Job timed out but did not complete."
}
$jobResults = Receive-Job $job
$jobResults
Stop-Job $job
Remove-Job $job