Search code examples
powershellazure-devopsazure-rest-api

InvalidRequestException when updating task group via REST api


I am trying to update a TaskGroup on our on-premise Azure DevOps 2020 server using REST api, but I am getting 500 InternalServerError

{"$id":"1","innerException":null,"message":"Input TaskGroup parameter cannot be null.","typeName":"Microsoft.TeamFoundation.DistributedTask.Server.Ex
ceptions.InvalidRequestException, Microsoft.TeamFoundation.DistributedTask.Server","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000}

The goal is to set visibleRule which isn't possible from the web interface.

$url = "http://{server}:8080/tfs/{organization}/{project}/_apis/distributedtask/taskgroups?api-version=6.1-preview.1"
$taskGroups = Invoke-RestMethod -Method Get -Uri $url -ContentType 'application/json' -UseDefaultCredentials

$taskGroup = $taskGroups.value | where { $_.name -eq "Deploy Task" }
$input = $taskGroup.inputs | where { $_.name -eq "VersionInternal" }
Add-Member -InputObject $input -MemberType NoteProperty -Name "visibleRule" -Value "1 = 2"

$json = $taskGroup | ConvertTo-Json -Depth 100
$response = Invoke-RestMethod -Method PUT -Uri $url -ContentType 'application/json' -Body $json -UseDefaultCredentials

What's wrong with the request? Is there any log file available? Or any other way to troubleshoot?


Solution

  • Based on what we have discussed previously, maybe, some things on your server or machine are restricting PowerShell to update the task groups.

    Anyhow, the Postman can work well as expected. So, the workaround is using Postman to call the REST API to update the task groups.