Created
July 18, 2022 05:08
-
-
Save ToroNZ/a805f46a784161da39083da598eac975 to your computer and use it in GitHub Desktop.
Migrate/Copy Azure Devops Variable Groups from a JSON file (plenty of room for improvement)
This file contains hidden or 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
import json | |
import argparse | |
from azure.cli.core import get_default_cli | |
# TODO: Wrap all required calls login/fetch/upload into a single call of this script or if you have time perform lookups and offer CLI style options | |
# Store JSON file from AZ CLI as: 'az pipelines variable-group show --group-id 136 --org "https://dev.azure.com/ORG/" --project "PROJECT NAME" --output json>136.json' | |
# Run as: 'python3 az-devops-import-variables.py -s 136.json -id 150 -project "project-uid" -org "https://dev.azure.com/ORG/"' | |
parser = argparse.ArgumentParser(description="Azure DevOps Variable import", formatter_class=argparse.RawTextHelpFormatter) | |
parser.add_argument('-s', type=argparse.FileType('r'), help="JSON File") | |
parser.add_argument('-id', help="Variable group id") | |
parser.add_argument('-org', help="Azure DevOps ORG") | |
parser.add_argument('-project', help="Azure DevOps Project name") | |
args = parser.parse_args() | |
j = json.load(args.s) | |
for variable, values in j['variables'].items(): | |
print(f"""Creating variable: {variable} in project "{args.project}" under ORG {args.org}...""") | |
get_default_cli().invoke(['pipelines', 'variable-group', 'variable', 'create', '--organization', str(args.org), '--project', str(args.project), '--group-id', args.id, '--name', str(variable), '--value', values['value']]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment