0

I have defined the following job template:

parameters:
- name: prefix
  type: string
- name: apps
  type: object
- name: containerRegistry
  type: string

jobs:
  job: Build Docker Images
  displayName: Build and Push image
  pool:
    vmImage: ubuntu-20.04
  steps:
  - checkout: self
  - ${{ each app in parameters.apps }}:
    - task: Docker@2
      displayName: Build and Push image
      inputs:
        containerRegistry: $(containerRegistry)
        repository: ${{ parameters.prefix }}/${{ app }}
        Dockerfile: apps/${{ app }}/Dockerfile
        tags: $(Build.BuildNumber)
        buildContext: $(Build.Repository.LocalPath)

which allows to easily build and push the docker images for the specified apps. I now need to pass the image names to the helm deploy tasks overrideValues parameter. However that parameter expects a string formatted as name=value,name=value. Is there a way to build this expression from the array? Eg something like

apps: ['hello', 'world']
prefix: 'app'

overrideValues: ${{ join(',', [$(app).image=$(prefix)/$(app) foreach app in apps]) }}
ACB
  • 1,607
  • 11
  • 31

1 Answers1

0

I managed to solve this with a powershell script. It was a bit tricky to get the parameter array into a powershell array but you can see the solution below:

    - pwsh: |
        $result = ''
        $apps = "${{ join('","', parameters.apps) }}"
        foreach($a in $apps) {
          $result += '{0}.image={1}/{0}:$(Build.BuildNumber),' -f $a, '${{ parameters.prefix }}'
        }
        $result = $result -replace '.$'
        Write-Host "##vso[task.setvariable variable=images;isOutput=true]$result"
        Write-Host $result
      name: GetImages
      displayName: Get Images for Helm
ACB
  • 1,607
  • 11
  • 31