Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script to update release pipeline variable with Azure DevOps REST API - a modified version of script available here
param (
[string] $VariableName,
[string] $VariableValue
## Construct a basic auth head using PAT
function BasicAuthHeader()
$ba = (":{0}" -f $authtoken)
$ba = [System.Text.Encoding]::UTF8.GetBytes($ba)
$ba = [System.Convert]::ToBase64String($ba)
$h = @{Authorization=("Basic{0}" -f $ba);ContentType="application/json"}
return $h
$h = BasicAuthHeader $env:SYSTEM_ACCESSTOKEN
$releaseId = $env:RELEASE_RELEASEID
$getReleaseUri = $baseRMUri + "/_apis/release/releases/" + $releaseId + "?api-version=5.0"
$release = Invoke-RestMethod -Uri $getReleaseUri -Headers $h -Method Get
# Update an existing variable named d1 to its new value d5
Write-Host ("Setting variable value...")
$release.variables.($VariableName).value = $VariableValue;
Write-Host ("Completed setting variable value.")
####****************** update the modified object **************************
$release2 = $release | ConvertTo-Json -Depth 100
$release2 = [Text.Encoding]::UTF8.GetBytes($release2)
$updateReleaseUri = $baseRMUri + "/_apis/release/releases/" + $releaseId + "?api-version=5.0”
Write-Host ("Updating release...")
$content2 = Invoke-RestMethod -Uri $updateReleaseUri -Method Put -Headers $h -ContentType “application/json” -Body $release2 -Verbose -Debug
write-host "=========================================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.