【发布时间】:2019-08-05 10:01:39
【问题描述】:
我正在尝试使用提供 Rest API documentation 更新发布管道的描述。
我应该如何发送“Put”请求以更新字段?
我尝试使用嗅探器手动修改和捕获请求,看来我的代码完全一样。
$theBody = ConvertTo-Json @{description='Added a description'}
$instance = "tfs:8080"
$collection = "Collection"
$project = "myProject"
$releaseID = 1234
$apiVersion = "?api-version=4.1-preview.6"
$URI = "http://"+$instance+"/"+$collection+"/"+$project+"/_apis/release/releases/"+$releaseID+$apiVersion
$res= Invoke-RestMethod -Method Put -Uri $URI -UseDefaultCredentials -Body $theBody -ContentType 'application/json'
write-output $res
我收到一条错误消息:
版本的 ID 与原始版本的 ID 不匹配 资源。确保您正在尝试更新正确的资源
【问题讨论】:
-
尝试使用
GET https://{instance}/{collection}/{project}/_apis/release/releases?api-version=5.0列出您的所有发布管道,并将您的 id 与响应 id 进行比较。和你用的一样吗? -
@MarTin 嘿,我可以使用上面的代码执行 GET 甚至是 Patch 请求,但似乎在 Put 请求中,无法完成单个变量更新。
标签: powershell azure-devops azure-pipelines-release-pipeline azure-devops-rest-api