Reputation: 327
I am trying to update the value of a single variable of a variable group using Az DevOps Rest API. As per my initial experiments, it doesn't seem to be possible?
This is what I have tried:
Say I have a variable group called : my-var-group
that has variables: my-variable-1:val1
my-variable-2:val2
And if I try :
curl -X PUT -H "Authorization: Bearer $token" -H "Content-Type:application/json" 'https://dev.azure.com/my-org/my-proj/_apis/distributedtask/variablegroups/201?api-version=5.1-preview.1' --data '{"variables":{"my-variable-1":{"value":"random1"}},"name":"my-var-group"}'
my-variable-1
is assigned value random1
but my-variable-2
is deleted. Is there anyway to only update one variable?
Upvotes: 2
Views: 886
Reputation: 40959
Here should be rather PATCH than PUT, but looking at documentation this is not possible.
I checked how it is done on Portal and there is used the same PUT endpoint as you mentioned. However, when you update there single value they still send all variables:
So as a workaround you may first get all variables, modify the one you need and send the back via PUT.
Other opiton could be Azure CLI
az pipelines variable-group variable update --group-id
--name
[--detect {false, true}]
[--new-name]
[--org]
[--project]
[--prompt-value {false, true}]
[--secret {false, true}]
[--subscription]
[--value]
which allows you to update single value. However, I don't know if this is an option for you.
Upvotes: 2