You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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"
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
The text was updated successfully, but these errors were encountered: