我们可以在管道定义中添加第一个任务power shell
并在变量选项卡中定义新变量,例如Value:true
,然后添加脚本以检查许可证状态,如果许可证可用,则将变量设置Value
为 true,如果许可证不可用,则设置变量Value
为 False。然后eq(variables['{variable name}'], '{variable value}')
在第二个任务中添加条件。
配置后,如果您的许可证可用,则管道将成功运行。
或者我们可以先检查许可证,然后调用下面的脚本来排队构建管道。
$token = "$(pat)"
$url = "https://dev.azure.com/{Org name}/{project name}/_apis/build/builds?api-version=6.1-preview.6"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON = @"
{
"definition": {
"id": {Build definition ID}
}
}
"@
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON
write-host $response