【发布时间】:2020-12-03 08:58:26
【问题描述】:
我正在使用本地 Azure DevOps API 使用以下 powershell 脚本更新版本定义:
$listurl="https://onpremdomain/{ogr}/{proj}/_apis/release/definitions?api-version=6.0"
$PAT="Personal access token"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
#get the releases' ids.
$result = Invoke-RestMethod -Uri $listurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
#loop the ids to get each release's definition
foreach($release in $result.value){
#get each release's definition
$definitionurl="https://onpremdomain/{ogr}/{proj}/_apis/release/definitions/$($release.id)?&api-version=6.0"
$releaseDefinition = Invoke-RestMethod -Uri $definitionurl-Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
#loop through each stage
foreach( $environment in $releaseDefinition.environments){
#loop through each tasks to find the task group
foreach($task in $environment.deployPhases.workflowTasks){
# change the 'taskId' to the taskId of your task group
if($task.taskId -eq "{taskId}"){
$task.version = "2.*" # update the taskgroup version to the newest version
}
}
}
$updateurl="https://onpremdomain/{ogr}/{proj}/_apis/release/definitions?api-version=6.0"
# update the release definition
Invoke-RestMethod -Uri $updateurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -ContentType "application/json" -Method PUT -Body (convertto-json $releaseDefinition -Depth 100)
}
当调用最后一行中的 Invoke-RestMethod 时,出现以下错误:
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"VS402903: The specified value is not convertible to type ReleaseDefinition. Make sure it is convertible to type ReleaseDefinition and
try again.","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestE
xception","errorCode":0,"eventId":3000}
知道为什么会出现这个错误吗?
【问题讨论】:
标签: powershell azure-devops azure-pipelines azure-devops-rest-api