I want to use json file to store variables used by powershell script. In azure devops I have configured pipeline, pipeline contains powershell script with a list of variables in it. I would like to use json file and store in this file all variables. I want to store json file in Azure repo, and use it once pipeline is started. I dont want to use variable groups. I found this solution [Json to Variable]https://marketplace.visualstudio.com/items?itemName=OneLuckiDev.json2variable&targetId=02fbae5c-cc01-4c8b-a90f-7393a3156347 but I read some uncomplimentary opinions about this task. Is there any method to use json file as a place to store variables, or maybe I can use different file format?
UPDATE:

1 Answer
Why not directly to use the Powershell built-in cmdlet: ConvertFrom-Json. See this official doc about this cmdlet description: Powershell: ConvertFrom-Json.
You can add the script:
Get-Content "{JSON file path}" | out-string | ConvertFrom-Json
Get-Content would read the JSON file into an array of strings, and ConvertFrom-Json convert these strings into the PSCustomObject object. Then you can call the exactly object with simple leverage dot notation(.), then use it with this format into the task script.
Here is the simple sample can for you refer:
$data = Get-content {your JSON file path}| out-string | ConvertFrom-Json
Write-Output $data.ts
Here I tried in my local Powershell-ISE which is same usage in Powershell task. ts is one of my JSON object. In azure devops, you can use the path like $(Build.SourcesDirectory)\..\..\...json to specified your file location if you store it in Repos.
8 Comments
$JsonFilePath = "$($Build.SourcesDirectory)\Variables.json" $JsonDataBase = Get-Content $($JsonFilePath) | out-string | ConvertFrom-Json and facing errors, file is stored in devops repo.Variable.json in located in the root path of your repos, right? Change your path script as $JsonFilePath = "$(Build.SourcesDirectory)\Variables.json" $JsonDataBase = Get-Content $JsonFilePath | out-string | ConvertFrom-Json. The method you used does not correct, because the correct path value should be d:\a\1\s\... instead of D:\.....$JsonFilePath = "$(Build.SourcesDirectory)\Variables.json", but still there is something wrong, now got an error like --> D:\a\1\s\Get-RbacReport.ps1 : The term 'Build.SourcesDirectory' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
echothe variables like so:echo "##vso[task.setvariable variable=a]20": learn.microsoft.com/en-us/azure/devops/pipelines/process/…