Created
August 23, 2019 09:37
-
-
Save xrisdoc/f4e635306118bd628bb52ff5960d2f2d to your computer and use it in GitHub Desktop.
PowerShell: Update Azure DevOps Release Variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Retrieve the current release | |
$releaseUrl = ('{0}{1}/_apis/release/releases/{2}?api-version=5.0' -f $($env:SYSTEM_TEAMFOUNDATIONSERVERURI), $($env:SYSTEM_TEAMPROJECTID), $($env:RELEASE_RELEASEID) ) | |
$release = Invoke-RestMethod -Uri $releaseUrl -Headers @{ | |
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" | |
} | |
# Set the relevant variables on the release | |
$release.variables."My.Test.Vari".value = "just a test" | |
$release.variables | Add-Member NoteProperty "My.Other.Test" ([PSCustomObject]@{value='test AGAIN'}) | |
$release.variables | Add-Member NoteProperty "Agent.BakFileToRestoreFrom" ([PSCustomObject]@{value='$(Agent.Output.DatabaseBakFileLocation)'}) | |
# Update the release to persist the changes made. | |
$json = @($release) | ConvertTo-Json -Depth 99 | |
Invoke-RestMethod -Uri $releaseUrl -Method Put -Body $json -ContentType "application/json" -Headers @{ | |
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment