We have a fairly complex pipeline which builds, tests and deploys our ASP.net MVC app to an Azure WebApp in an App Service Environment. Because we have several high profile customers we actually deploy the app to separate web apps for each customer ‘instance’ so they have database and application isolation.

Because each customer instance is identical except for some App Settings to point to a separate database; deployment is the same except the web app location. Currently we have a Task Group with parameters setting the name of the instance (for the Task Display Name), the app location and the staging url so we can run tests.

I would prefer to use the new YAML pipeline for this app so its easier to add new customer 'instances’ in the future and we can source control the pipeline.

After some investigation, I discovered I can pass parameter 'objects’ into a template YAML file to pretty much do what I want; the only tricky bit was to have multiple properties per instance parameter 'object’ and using the new template {{ each }} expression.

Below is how I constructed my yaml files for this solution.

azure_pipelines.yml

pool:
  name: Hosted VS2017
  demands:
  - npm
  - msbuild
  - visualstudio
  - vstest

steps:
- template: azure_webapp_template.yml
  parameters:
    webapps:
    - name: Customer 1
      url: customer1.azurewebsites.net
    - name: Customer 2
      url: customer2.azurewebsites.net
    - name: Customer 3
      url: customer3.azurewebsites.net
    - name: Customer 4
      url: customer4.azurewebsites.net

As you can see above, we are creating an object webapps and then we have some nested properties for each 'webapp’.

Then in our 'template’ we can iterate over each of the objects in the webapps parameter and expand the property in our iterated tasks.

azure_webapp_template.yml

# Proving ability to loop over params a number of times

parameters:
- name: 'webapps'
  type: object
  default: {}

steps:
- ${{ each webapp in parameters.webapps }}:

  - task: PowerShell@2
    displayName: 'Task Group Test 1 ${{webapp.name}}'
    inputs:
      targetType: 'inline'
      script: |
        Write-Host "Name: ${{webapp.name}} with url ${{webapp.url}}"
      failOnStderr: true
      workingDirectory: '$(Build.SourcesDirectory)'

  - task: PowerShell@2
    displayName: 'Task Group Test 2 ${{webapp.name}}'
    inputs:
      targetType: 'inline'
      script: |
        Write-Host "Name: ${{webapp.name}} with url ${{webapp.url}}"
      failOnStderr: true
      workingDirectory: '$(Build.SourcesDirectory)'

I hope this finds some use to others.