Search code examples
azure-devopsdeploymentazure-resource-managerazure-rm-template

How to override the object and array parameters in the Arm template?


I want to override the parameters of an object or array within the Arm Template. How can I pass the new values to the template from the task?

I use the following task:

    - task: AzureResourceManagerTemplateDeployment@3
      displayName: "Create Container App"
      inputs:
         deploymentScope: 'Resource Group'
         azureResourceManagerConnection: '$(serviceConnection)'
         subscriptionId: '$(SubscriptionID)'
         action: 'Create Or Update Resource Group'
         resourceGroupName: '$(ResourceGroup)'
         location: 'West Europe'
         templateLocation: 'Linked artifact'
         csmFile: '$(Pipeline.Workspace)/drop/armtemplates/container_deployment.json'
         csmParametersFile: '$(Pipeline.Workspace)/drop/armtemplates/container_parameters.json'
         deploymentMode: 'Incremental'
         overrideParameters: '-SubscriptionId $(SubscriptionID) -containers $(ContainerAppName) -ResourceGroup $(ResourceGroup) -BuildID $($(Build.BuildId)) -RegistriesServer $(RegistriesServer) -RepositoryAppName $(RepositoryAppName) -ContainerAppEnvironment $(ContainerAppEnvironment) -UserIdentityName $(UserIdentityName)'
      continueOnError: false

In the example task above, I don't know how to pass a new value to the parameter (containers -> value -> name) in the parameter.json file which has the parameter (as an object) containers (see below). I need to change the name and image values. How can I override those parameters? How do I pass the new value?

        "containers": {
        "value": [
            {
                "name": "$(ContainerAppName)",
                "image": "$(containerAppImageName)",
                "command": [],
                "args": [],
                "resources": {
                    "cpu": 0.5,
                    "memory": "1Gi"
                }
            }
        ]
    }

I was not able to find the correct solution.

I am using AzureResourceManagerTemplateDeployment@3 as the deployment task.

The post about How to pass azure pipeline variables is not the same as my question. I need to know how to override the parameter within an object or array. I hope that this is clear.


Solution

  • Please check the task doc for overrideParamters below:

    enter image description here

    The trick is you can classic UI task to help find the correct definition.

    Select template.json and paramter.json, then you can click ... button to override parameters, it will pop up the parameters and it's default value, you can use variables for the value then.

    enter image description here

    You can see the yaml by clicking the View Yaml button, then copy the overrideParamters to your real yaml.

    enter image description here