Created
April 8, 2022 07:57
-
-
Save geralexgr/f669729859833a2a199204e895e47869 to your computer and use it in GitHub Desktop.
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
trigger: | |
- none | |
pr: none | |
pool: | |
vmImage: ubuntu-latest | |
variables: | |
- group: token-group | |
steps: | |
- task: PowerShell@2 | |
displayName: Get variables from variable-group | |
inputs: | |
targetType: 'inline' | |
script: | | |
$connectionToken="$(PAT)" | |
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)")) | |
$URL = "https://dev.azure.com/geralexgr/test-project/_apis/distributedtask/variablegroups?groupIds=5&api-version=7.1-preview.1" | |
$Result = Invoke-RestMethod -Uri $URL -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get | |
$Variable = $Result.value.variables | ConvertTo-Json -Depth 100 | |
Write-Host $Variable | |
- task: PowerShell@2 | |
displayName: add variables on variable-group | |
inputs: | |
targetType: 'inline' | |
script: | | |
$connectionToken="$(PAT)" | |
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)")) | |
$URL = "https://dev.azure.com/GeralexGR/test-project/_apis/distributedtask/variablegroups/5?api-version=5.1-preview.1" | |
$body = '{"id":5,"type":"Vsts","name":"var-group","variables":{"rest-var1":{"isSecret":false,"value":"rest-var-value-1"},"rest-var2":{"isSecret":false,"value":"rest-var-value-2"},"rest-var3":{"isSecret":false,"value":"rest-var-value-3"}}}' | |
$Result = Invoke-RestMethod -Uri $URL -Headers @{authorization = "Basic $base64AuthInfo"} -Method Put -Body $body -ContentType "application/json" | |
$Variable = $Result.value.variables | ConvertTo-Json -Depth 100 | |
Write-Host $Variable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment