Reputation: 403
I am trying to programmatically update the value of a variable in a Team Services build definition, using the REST API documented at https://www.visualstudio.com/en-us/docs/integrate/api/build/definitions and a PowerShell Script.
So the plan is to read the definition using a GET, modify the value in the returned object and then update the definition using a PUT.
My problem is that the last step (PUT) fails with an Exception (seemingly in the server side). The same exception is thrown even if I don't modify anything in the definition.
So in the simplest terms the 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 the exception I get is:
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}
I think I am using the API as described in the documentation, but I may be missing something.
Upvotes: 4
Views: 1007