0

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?

horato
  • 65
  • 7
  • I attempted the similar PowerShell script on my side and found that the line `$taskGroup = $taskGroups.value | where { $_.name -eq "Deploy Task" }` actually would return an empty value. That should be the reason why the final 500 error states that the parameter is null. I did further investigation, found that `$taskGroups.value` returned the empty value. However, the `$taskGroups` can return the correct value as expected. Not sure why the `$taskGroups.value` returns an empty value, it looks like an issue on the PowerShell. I tried on PowerShell 5 and PowerShell 7, have the same issue. – Bright Ran-MSFT Nov 29 '22 at 07:56
  • @BrightRan-MSFT Isn't that because there's no task group named "Deploy Task" in your DevOps instance? I get the same response even if I edit the task group through the web interface, copy the request body and send it through soapui. – horato Nov 29 '22 at 10:54
  • Hi @horato, When I tested, I has replaced "Deploy Task" with the name of an existing task group in my Azure DevOps project. So, the name is not the problem. Maybe, you can try the REST API on Postman to see if it can work. If the same issue exists, the problem should be on the API. If it can work on Postman, the problem should be on PowerShell or your script itself. – Bright Ran-MSFT Nov 30 '22 at 02:10
  • Hi @horato, I tried again with the almost same PowerShell script as yours, except the names of instances are owned myself. The script can work well on my side. I made a mistake previously caused `$taskGroups.value` returned the empty value and have resolved it. Anyway, I can confirm your script is OK, the REST API is OK. As suggested in my last comment, please try calling the REST API on Postman or other similar tools to see if the same issue exists. If same issue exists, the problem may be on your Server itself. If possible, you can try to restart your Server to see if the issue can be fixed. – Bright Ran-MSFT Nov 30 '22 at 10:34
  • @BrightRan-MSFT Hey, for whatever reason postman works, but soapui doesn't. I am guessing it has something to do with the TaskGroup Tasks' content. I am just gonna ditch the whole powershell thing and do the one time update through postman with the request generated from DevOps web interface. Thanks! – horato Nov 30 '22 at 11:07
  • Hi @horato, Glad that using Postman can work for you. So, the workaround is using Postman to call the REST API to update the task groups. – Bright Ran-MSFT Dec 01 '22 at 12:28

1 Answers1

0

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.

Bright Ran-MSFT
  • 5,190
  • 1
  • 5
  • 12