Skip to content

Instantly share code, notes, and snippets.

@slmcmahon
Created October 11, 2023 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slmcmahon/a5218a0688092bdf0df7d0b114016981 to your computer and use it in GitHub Desktop.
Save slmcmahon/a5218a0688092bdf0df7d0b114016981 to your computer and use it in GitHub Desktop.
Compares two variable lists and reports variables that don't match
import json
import requests
import os
from requests.auth import HTTPBasicAuth
org = 'your-org'
project = 'your-project'
# the variableGroupId values from the variable libs that
# you want to compare
lib1 = 2460
lib2 = 3105
url = f'https://dev.azure.com/{org}/{project}/_apis/distributedtask/variablegroups?groupIds={lib1},{lib2}&api-version=6.0-preview.2'
rsp = requests.get(url, auth=HTTPBasicAuth('user', os.environ['AZDO_PAT']))
data = json.loads(rsp.content.decode('utf-8'))
varnamelist = []
for varlist in data['value']:
# this gets all of the variables for the id selected above
varnames = [l for l in varlist['variables']]
varnamelist.append({'id': varlist['id'], 'name': varlist['name'], 'vars': varnames})
lists_equal = len(varnamelist[0]['vars']) == len(varnamelist[1]['vars'])
print(f'Lists are equal: {lists_equal}')
if not lists_equal:
print(f'variables in {varnamelist[0]["name"]} but not in {varnamelist[1]["name"]}')
print(", ".join(list(set(varnamelist[0]['vars']) - set(varnamelist[1]['vars']))))
print(f'variables in {varnamelist[1]["name"]} but not in {varnamelist[0]["name"]}')
print(", ".join(list(set(varnamelist[1]['vars']) - set(varnamelist[0]['vars']))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment