How to update Team Team Visual Studio build definition using REST api?

I am trying to programmatically update a variable value in a Team Services assembly definition using the REST API registered at https://www.visualstudio.com/en-us/docs/integrate/api/build/definitions and PowerShell Script.

So, the plan is to read the definition using GET, change the value in the returned object, and then update the definition using PUT.

My problem is that the last step (PUT) fails with the Exception (seems to be on the server side). The same exception is thrown even if I do not change anything in the definition.

So, the simplest term for PowerShell code would be:

$definitionId = 27
$url = "https://imaginera.visualstudio.com/DefaultCollection/Fidelis/_apis/build/definitions/" + $definitionId + "?api-version=2.0"

# Read the build definition.
$definition = Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Get -Uri $url 

# Update the build definition.
Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Put -Uri $url -Body (ConvertTo-Json $definition) -ContentType "application/json"

And I get the following:

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: definition.Options[0].Definition","typeName":"System.ArgumentNullException, mscorlib, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}

, API, , - .

+4
1

-Depth ConvertTo-Json.

+5

Source: https://habr.com/ru/post/1672169/


All Articles