1

Is there any way to pass a variable group name to a release pipeline using REST API without editing the release definition.

I am able to do it using the following

   $defurl = "https://vsrm.dev.azure.com/org/proj/_apis/release/definitions/13?api-version=5.1" 
   $def = Invoke-RestMethod -Uri $defurl -Method Get -Headers $header
   $def.variableGroups="VariableGroupName"
   $json = @($def) | ConvertTo-Json -Depth 99 
   $udef = Invoke-RestMethod  -Uri $defurl  -Method Put -Body $json -ContentType "application/json" -Headers $header

But the problem is "Put" request updating the Original definition. Is there any way to pass the Variablegroup without editing the release definition. Is this a good practice to edit the Release defnition on the fly to pass the variable group.

6
  • Can you tell us what $definition looks like? Commented Dec 4, 2019 at 11:02
  • $definition is a Json Object Commented Dec 4, 2019 at 14:50
  • I see, but what I meant was: you are updating the definition with $def.variableGroups="VariableGroupName". Shouldn't you convert $def to json and use that in your next Invoke-RestMethod call rather than $definition ? Commented Dec 4, 2019 at 14:53
  • yes i do , Sorry for the typo My problem is I want to pass the variable without updating\editing the definition Commented Dec 4, 2019 at 15:12
  • I have found that most(all?) of the actions in the web gui call the REST api, so you can use fiddler to capture the calls your browser makes when you perform the action manually in the web gui, and inspect what the json looks like there, which may give you some insight. Commented Dec 5, 2019 at 16:49

2 Answers 2

1

Is there any way to pass the Variablegroup without editing the release definition

I am afraid there is no such way to pass the Variablegroup without editing the release definition.

To pass the Variablegroup name to the release definition, we have to use the Put request to update the definition. Since there is no option/REST API we could use to update the definition when we run the release pipeline.

If you do not want to modify the original definition, you could get the Variablegroup name in the original definition, then use above REST API to add/update the Variablegroup name. At the end of the release pipeline, we could invoke again above REST API to restore the Variablegroup name in the original definition.

Besides, if there are not many variables in the variable group you added, you could use the the Logging Command during the release pipeline to overwrite the variables, which would not change the original definition.

Write-Host "##vso[task.setvariable variable=testvar;]testvalue"

Update:

How to use this logging command outside the release pipeline to modify the Variable group???

The answer is NO. That because we could not update the the variable group when we create the release pipeline, it only shows the release variable:

enter image description here

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

How to use this logging command outside the release pipeline to modify the Variable group???
@tjdoubts, If you want to use this logging command outside the release pipeline to modify the Variable group, I am afraid the answer is NO, you could check my updated answer for some more details.
0

You are using the same $defurl with a get, then a post. The post is trying to perform an update on the definition api doc src so this code will always update the release definition.

I think the endpoint you are looking for is release -> Create which will start a new deployment. I have not modified Variable Groups using this endpoint, but have overrode specific variables and will try to add some code to my answer if a better answer does not pop up.

I found that using fiddler to inspect the REST calls that the web gui sends helped me figure out exactly how my json body needed to look like.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.