Jac*_*Orr 4 yaml azure-resource-manager azure-pipelines
尝试运行管道时出现错误。
/devops/templates/app-deployment-template.yml(行:50,列:27):无法从数组转换为字符串。值:数组
这是我的 yaml 文件中的参数,我试图将其进一步传递到 ARM 模板中。在顶层,这是一个字符串数组,其中包含 UKSouth、NorthEurope 等元素。
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}}'
Run Code Online (Sandbox Code Playgroud)
小智 5
这是因为您${{parameters.locations}}被定义为 YAML 数组,这意味着它看起来像这样:
locations:
- region1
- region2
- region3
Run Code Online (Sandbox Code Playgroud)
或者
locations: [region1, region2, region3]
Run Code Online (Sandbox Code Playgroud)
引擎不理解如何正确地展平数组并将其变成字符串,您应该能够通过以下任一/或一种方式解决它:
使用convertToJson表达式
${{ convertToJson(parameters.locations) }}
这将帮助引擎将 YAML 数组转换为 JSON 字符串,ARM 将接受该字符串,因为它基于 JSON。
或者
更改位置参数以直接将其视为字符串,并将位置的输入设置为 ARM 的 JSON 格式:
locations: >
["region1","region2","region3"]
Run Code Online (Sandbox Code Playgroud)
parameters:
- name: locations
type: string
default: '[]'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7099 次 |
| 最近记录: |