我正在尝试批准 azure devops 中的多阶段 yaml 管道的各个阶段,但我对端点的 REST 请求详情此处返回错误
{"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: updateParameters","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}
我遵循的策略是从管道的时间线中获取批准 ID(记录在此处),然后获取批准详细信息(记录在此处),这给了我 2 个对象:
时间线的批准阶段
{
"previousAttempts": [
],
"id": "e23aa595-7745-4015-9fdd-be7863faeda1",
"parentId": "4ae2b754-452d-5a7c-1d05-4887a615523a",
"type": "Checkpoint.Approval",
"name": "Checkpoint.Approval",
"startTime": "2023-11-15T12:36:50.5633333Z",
"finishTime": null,
"currentOperation": null,
"percentComplete": null,
"state": "inProgress",
"result": null,
"resultCode": null,
"changeId": 71,
"lastModified": "0001-01-01T00:00:00",
"workerName": null,
"details": null,
"errorCount": 0,
"warningCount": 0,
"url": null,
"log": null,
"task": null,
"attempt": 1,
"identifier": "e23aa595-7745-4015-9fdd-be7863faeda1"
}
并直接从 GET 请求获得批准
{
"id": "e23aa595-7745-4015-9fdd-be7863faeda1",
"steps": [
],
"status": "pending",
"createdOn": "2023-11-15T12:36:50.53Z",
"lastModifiedOn": "2023-11-15T12:36:50.531529Z",
"executionOrder": "anyOrder",
"minRequiredApprovers": 1,
"blockedApprovers": [
],
"_links": {
"self": {
"href": "https://dev.azure.com/<orgName>/8f6c8014-5c15-49aa-8efc-adb274f30be3/_apis/pipelines/approvals/e23aa595-7745-4015-9fdd-be7863faeda1"
}
},
"pipeline": {
"owner": {
"_links": "@{web=; self=}",
"id": 23633,
"name": "20231115.7"
},
"id": "64",
"name": "Traveller"
}
}
然后我构建了 PATCH 主体
[
{
"status": "approved",
"approvalId": "e23aa595-7745-4015-9fdd-be7863faeda1",
"comment": ""
}
]
并将其发送到端点
https://dev.azure.com/<orgName>/<projectname>/_apis/pipelines/approvals?api-version=7.1-preview.
有关此主题的所有文档和其他问题都表明我做得正确,但我无法克服此错误。
我直接在请求中使用了json内容。这是我的样本供您参考。
$organization = "Org"
$project = "Project"
$MyPat = 'xxxxx'
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$MyPat"))
$URL = "https://dev.azure.com/$organization/$project/_apis/pipelines/approvals?api-version=7.1-preview.1"
$header = @{
'Authorization' = 'Basic ' + $B64Pat
'Content-Type' = 'application/json'
}
$body = @"
[
{
"status": "approved",
"approvalId": "2c8f92ed-6c78-4ccb-8cb6-59afec19cec2",
"comment": ""
}
]
"@
$response = Invoke-RestMethod -Method PATCH -Uri $URL -Headers $header -Body $body | ConvertTo-Json