我试图从powershell运行下面的API 'Patch‘命令,我想在Azure DevOps中执行一个发行版.
$deploy = Invoke-RestMethod -Uri $patchurl -Method Patch -Body $body -Headers $header -ContentType "application/json-patch+json"下面是url示例
https://vsrm.dev.azure.com/test/Fixed%20Income/_apis/Release/releases/567/environments/1072?api-version=6.0-preview.6贴片呼叫的身体是..。
"Status": "inProgress",
"scheduledDeploymentTime": null,
"comment": null,
"variables": {}从powershell运行invoke命令将返回以下响应.
调用-eventId方法:{"$id":"1","innerException":null,“消息”:“TF400898:发生内部错误。”活动Id: 759888ab-9828-4cb6-ba2f-e90cde1cd39a。“,System.Web.Http","typeKey":"HttpResponseException","errorCode":0,"eventId":0}
当我运行相同的url来运行邮递员的“补丁”请求时,我会得到下面的响应,这就是我期望从Powershell获得的响应。
"$id":"1","innerException":null,"message":"TF400813:用户'‘未被授权访问该资源。“,"typeName":Microsoft.TeamFoundation.Framework.Server,"typeKey":"UnauthorizedRequestException","errorCode":0,"eventId":3000
知道我做错什么了吗?
发布于 2020-11-05 03:23:01
根据您的描述,当您从邮递员调用此REST API时,响应将返回一个错误:"message":"TF400813: user“未被授权访问此资源。”此问题的原因是授权不正确。
请先在组织中创建一个新的个人访问令牌,然后在授权选项卡中选择类型:Basic Auth,然后在右侧的密码输入框中键入PAT。

当您从powershell调用此REST时,响应返回一个错误:"TF400898:发生了内部错误。活动Id: 759888ab-9828-4cb6-ba2f-e90cde1cd39a“。造成此问题的原因是内容类型不正确。
请使用ContentType ContentType代替ContentType“application/json-补丁+json”。
Script template:
$token = "PAT"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$url3="https://vsrm.dev.azure.com/{organization}/{project}/_apis/Release/releases/{releaseId}/environments/{environmentId}?api-version=6.0-preview.6"
$body = "{
`"status`": `"inProgress`",
`"scheduledDeploymentTime`": null,
`"comment`": null,
`"variables`": {}
}"
$response3 = Invoke-RestMethod -Uri $url3 -Headers @{Authorization = "Basic $token"} -Method Patch -Body $body -ContentType application/json请参考创建PAT的以下步骤


https://stackoverflow.com/questions/64684377
复制相似问题