Jack
Jack

Reputation: 307

Azure Pipelines: Unexpected symbol Located within expression when using YAML each

having issues with a change I'm trying to make to our Azure Pipelines. Currently we deploy this api to a single region and we'd like to deploy in multiple regions. I've updated the ARM templates using the copy function so that the infrastructure (storage accounts, app service plans, etc) will be deployed to the different regions, the issue appears to be with the yml that subsequently deploys the api.

We have top level yml files for different purposes like pr.yml, ci.yml, release.yml. They are pretty generic and make use of templates for builds, deployments, etc.

For example, ci.yml (with keys etc removed):

variables:
  vmImage: windows-2022
  testVmImage: windows-latest
  resourceGroupName: abc
  apiName: xyz
  locations: 
    -North Europe
    -Australia East

stages:  
- stage: Build
  displayName: 'Build stage'
  jobs:
  - template: templates/app-build-template.yml
    parameters:
      buildConfiguration: 'Release'
      buildPlatform: 'Any CPU'

- stage: Deploy
  displayName: 'Deploy - Staging'
  dependsOn:
    - Build
  jobs:
  - template: templates/app-deployment-template.yml
    parameters:
      vmImage: $(vmImage)
      environmentName: ci
      subscriptionName: 'Subscription Name'
      subscriptionId: 'Subscription Id'
      resourceGroupName: $(resourceGroupName)
      apiName: $(apiName)
      slotName: 'staging'
      locations: $(locations)

Then in app-deployment-template.yml, I'm trying to loop over the list of locations, repeating the function app deployment task.

parameters:
- name: vmImage 
  type: string 
- name: environmentName 
  type: string 
- name: subscriptionName
  type: string
- name: subscriptionId
  type: string
- name: resourceGroupName
  type: string
- name: apiName
  type: string
- name: slotName 
  type: string
- name: locations
  type: object
  default: [] 

jobs:   
- job: DeployInfrastructure
  displayName: 'Deploy Infrastructure and App'
  pool:
    vmImage: ${{parameters.vmImage}}  
  steps: 
  - task: DownloadBuildArtifacts@0
    inputs:
       buildType: 'current'
       downloadType: 'single'
       artifactName: 'artifacts'
       downloadPath: '$(Pipeline.Workspace)'

  - ${{ each location in parameters.locations }}:
    - task: AzureFunctionApp@1
      inputs:
        azureResourceManagerConnection: '${{parameters.subscriptionName}}'
        subscriptionId: '${{parameters.subscriptionId}}'
        azureSubscription: '${{parameters.subscriptionName}}'
        appType: 'functionApp'
        appName: '${{parameters.environmentName}}${{parameters.apiName}${{location}}'
        resourceGroupName: '${{parameters.environmentName}}${{parameters.resourceGroupName}}'
        deployToSlotOrASE: true
        slotName: ${{parameters.slotName}}
        package: '$(Pipeline.Workspace)/artifacts/FunctionApp/FunctionAppName.zip' 

Unfortunately I get a validation error when attempting to validate/run the pipeline.

/devops/templates/app-deployment-template.yml (Line: 45, Col: 18): Unexpected symbol: 'apiName}${{location'. Located at position 12 within expression: parameters.apiName}${{location. For more help, refer to https://go.microsoft.com/fwlink/?linkid=842996

Any help would be appreciated, thanks.

Upvotes: 2

Views: 4305

Answers (1)

Daniel Mann
Daniel Mann

Reputation: 58981

You're missing a } in the line

appName: '${{parameters.environmentName}}${{parameters.apiName}${{location}}'

Specifically, ${{parameters.apiName}.

Upvotes: 1

Related Questions