3

Getting an error when trying to run a pipeline.

/devops/templates/app-deployment-template.yml (Line: 50, Col: 27): Unable to convert from Array to String. Value: Array

This is the parameter in my yaml file that I'm trying to pass further down into an ARM template. At the top level, this is a string array with elements such as UKSouth, NorthEurope, etc.

parameters:
- name: locations
  type: object
  default: [] 
  # other parameters
  # other jobs and tasks

  - task: AzureResourceManagerTemplateDeployment@3
    displayName: 'Deploy Azure Core Infrastructure'
    inputs:
      deploymentScope: 'Resource Group'
      azureResourceManagerConnection: '${{parameters.subscriptionName}}'
      action: 'Create Or Update Resource Group'
      resourceGroupName: '${{parameters.environmentName}}-${{parameters.resourceGroupName}}'
      location: 'North Europe'
      templateLocation: 'Linked artifact'
      csmFile: '$(Pipeline.Workspace)/artifacts/infrastructure/appserviceplan.json'
      csmParametersFile: '$(Pipeline.Workspace)/artifacts/infrastructure/appserviceplan.parameters.json'
      deploymentMode: 'Incremental'
      overrideParameters: '-name ${{parameters.environmentName}}-${{parameters.resourceGroupName}} -locations ${{parameters.locations}}'    
Jack
  • 237
  • 1
  • 4
  • 14
  • 2
    Have you seen this post: https://stackoverflow.com/questions/59972329/how-to-pass-complex-devops-pipeline-template-parameter-to-script ? – Thomas Aug 15 '22 at 06:25

1 Answers1

2

That is because your ${{parameters.locations}} is defined as an YAML-array, meaning it looks something like this:

locations:
- region1
- region2
- region3

or

locations: [region1, region2, region3]

The engine does not understand how to properly flatten the array and make it into a string, you should be able solve it in either/or of the following ways:

Use the convertToJson expression
${{ convertToJson(parameters.locations) }}
This will help the engine with converting the YAML-array into a JSON-string, which ARM will accept as it is based on JSON.

or

Change the parameter for locations to directly be considered a string and set the input for location to already be in JSON-format for ARM:

locations: >
 ["region1","region2","region3"]
parameters:
- name: locations
  type: string
  default: '[]'
GalnaGreta
  • 21
  • 2