How to use the Json Variables in Azure DevOps YAML Pipeline?

Shekhar Khadka 5 Reputation points
2023-08-01T01:51:24.5333333+00:00

I want to deploy the azure resources(ADF) and while deploying I need to override some DEV ARM template parameters and one of the parameters to deploy is of JSON OBJECT which I store its value in the pipeline Variable Group as below,

User's image

Actually the value looks like this {"minutes":[00],"hours":[5],"weekDays":["Monday","Tuesday","Wednesday","Thursday","Friday"]}

Since in azure DevOps pipeline, every Variable value that we fetch will be treated as a string type but my parameter for the ARM template need the value of Json type.

- task: AzurePowerShell@5
      displayName: Deploy ADF
      inputs:
        azureSubscription: '$(azureSubscription)'
        ScriptType: 'InlineScript'
        Inline: 

          New-AzResourceGroupDeployment `
             -ResourceGroupName "$(DeploymentResourceGroupName)" `
             -TemplateParameterFile "$(System.DefaultWorkingDirectory)/$(SourceDataFactoryName)/ARMTemplateParametersForFactory.json" `
             -TemplateFile "$(System.DefaultWorkingDirectory)/$(SourceDataFactoryName)/ARMTemplateForFactory.json" `
             -factoryName "$(DeployDataFactoryName)" `
             -LocalTesting_properties_typeProperties_recurrence_schedule $Trigger_Schedule `
             #
Community Center Not monitored
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 23,385 Reputation points Volunteer Moderator
    2023-08-01T03:29:26.96+00:00

    You can pass JSON object as a string to the pipeline just need to replace " with "

    For example this YAML file:

    steps:
    - task: AzureResourceManagerTemplateDeployment@3
      inputs:
        deploymentScope: 'Resource Group'  # Change this to 'Subscription' if needed
        azureResourceManagerConnection: 'YourAzureServiceConnection'  # Replace with your service connection name
        subscriptionId: 'YourSubscriptionId'
        action: 'Create Or Update Resource Group'
        resourceGroupName: 'YourResourceGroupName'
        location: 'YourResourceGroupLocation'
        templateLocation: 'Linked artifact'
        csmFile: 'path/to/your/template.json'  # Path to your ARM template file
        csmParametersFile: 'path/to/your/parameters.json'  # Path to a JSON file containing parameters (if needed)
        overrideParameters: '-MyJsonObjectParameter "{\"minutes\":[00],\"hours\":[5],\"weekDays\":[\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\"]}"'
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.