【发布时间】:2021-12-09 03:52:53
【问题描述】:
所以在这里我有一部分代码,我试图弄清楚如何在 while 循环中运行命令 x 次并结束脚本。
$timer = New-TimeSpan -Minutes 120
$sw = [diagnostics.stopwatch]::StartNew()
while ($sw.elapsed -lt $timer) {
$ReleaseStatus = Invoke-RestMethod -Uri "https://vsrm.dev.azure.com/company/Project/_apis/release/releases/$RId/environments/$EId/?`api-version=6.0" -Method GET -Headers $Header -Verbose
start-sleep -seconds 10
#if release is successful return message and end script.
if ($ReleaseStatus.Status -eq 'Succeeded') {
write-host "Release Succeeded"
return
}
#if the release fails run the command x number of times.
if ($ReleaseStatus.status -eq 'Rejected') {
Write-Host "Release failed, Re-running release for you"
#input command here to run release x number of times and then end whole script.
}
}
我尝试了各种方法,但没有成功,有人知道我该怎么做吗?
【问题讨论】:
-
您确定
Invoke-RestMethod返回一个具有Status属性的对象吗? -
是的,我已经对其进行了彻底的测试,它返回了状态属性,因此我在我的“if”语句中使用了该表达式。
标签: powershell azure-devops scripting