Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update a release pipeline variable with 'dot' in its name? #54

Closed
PraveenKalavai opened this issue Aug 10, 2020 · 1 comment
Closed

Comments

@PraveenKalavai
Copy link

I'm trying to update a release pipeline variable during release in a PowerShell task, with a Rest API call.
But it is throwing error since the variable has 'dot' in it.
Here is the variable : folders.0.environments.0.variables.0.value
It corresponds to a path in a json file which I would like to update during the release pipeline and use in the json file in a subsequent task.
So, how do I handle updating such pipeline variables with dot in them?
The script runs perfectly fine if I try to update a normal variable like "variable1".

  • Here is the code snippet if anyone would like to try and help resolve the issue.

  • Allow the Agent job to "Allow scripts to access the OAuth token"

  • Have a variable with 'dot' in it and make it "settable at release time"

  • Allow "edit release pipeline" in the security

$url = "https://vsrm.dev.azure.com/{Org}/{Project}/_apis/Release/definitions/$($env:RELEASE_DEFINITIONID)?api-version=5.0"

$ba = (":{0}" -f $env:SYSTEM_ACCESSTOKEN)
$ba = [System.Text.Encoding]::UTF8.GetBytes($ba)
$ba = [System.Convert]::ToBase64String($ba)
$header = @{Authorization=("Basic{0}" -f $ba);ContentType="application/json"}
$pipeline = Invoke-RestMethod -Uri $url -Headers $header 
Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"

write-host "==========================================================" 
write-host "Update an existing variable named "folders.0.environments.0.variables.0.value" to its new value "
write-host "==========================================================" 

$pipeline.variables.folders.0.environments.0.variables.0.value.value = "updated value"

# $pipeline.variables.variablename.value = "updated value"
# works if variable value does not have a dot in it.
# example : $pipeline.variables.variable1.value = "updated value"  

#****************** update the modified object **************************
$json = @($pipeline) | ConvertTo-Json -Depth 99

$updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers $header

@PraveenKalavai
Copy link
Author

PraveenKalavai commented Aug 11, 2020

Figured it out!
I just had to use the variable with quotes.
ex: $pipeline.variables.'folders.0.environments.0.variables.0.value'.value = "updated value"

Closing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant