如何使用 PowerShell 自动批准预部署批准 Azure DevOps?
How to automatically approve pre-deployment approval Azure DevOps using PowerShell?
我正在尝试使用 Rest API 自动执行发布部署。以下是步骤:
- 获取最新版本。
- 使用 API 部署特定阶段。
- 自动批准部署前批准。
所以我卡在了第 3 步,有没有办法使用 API.
绕过或自动批准此操作?
您可以使用 Approvals - Update Rest API. first you need to get all the approvals (for the id
) with Approvals - List,通过发布 ID 筛选批准,然后批准。
例如:
$approvalsUrl = "https://vsrm.dev.azure.com/{org}/{project}/_apis/release/approvals?api-version=6.0"
$token = "PAT"
$script:Base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User, $token)))
$header = @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
$response = Invoke-RestMethod -Uri $approvalsUrl -Method Get -Headers $header
$latestReleaseId = 1111
$id = $response.value.Where({ $_.release.id -eq $latestReleaseId }).id
# approve
$body = '{
"status": "approved",
"comments": "Good to go"
}'
$approvalUrl = "https://vsrm.dev.azure.com/{org}/{project}/_apis/release/approvals/$($id)?api-version=6.0"
$response = Invoke-RestMethod -Uri $approvalUrl -Method Patch -Headers $header -Body $body -ContentType application/json
我正在尝试使用 Rest API 自动执行发布部署。以下是步骤:
- 获取最新版本。
- 使用 API 部署特定阶段。
- 自动批准部署前批准。
所以我卡在了第 3 步,有没有办法使用 API.
绕过或自动批准此操作?您可以使用 Approvals - Update Rest API. first you need to get all the approvals (for the id
) with Approvals - List,通过发布 ID 筛选批准,然后批准。
例如:
$approvalsUrl = "https://vsrm.dev.azure.com/{org}/{project}/_apis/release/approvals?api-version=6.0"
$token = "PAT"
$script:Base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User, $token)))
$header = @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
$response = Invoke-RestMethod -Uri $approvalsUrl -Method Get -Headers $header
$latestReleaseId = 1111
$id = $response.value.Where({ $_.release.id -eq $latestReleaseId }).id
# approve
$body = '{
"status": "approved",
"comments": "Good to go"
}'
$approvalUrl = "https://vsrm.dev.azure.com/{org}/{project}/_apis/release/approvals/$($id)?api-version=6.0"
$response = Invoke-RestMethod -Uri $approvalUrl -Method Patch -Headers $header -Body $body -ContentType application/json