title: array to string in yaml with bindings to variables
body: <p>I'm trying to create azure pipeline and one part of it is using task AzureResourceGroupDeployment, which takes in overrideParameters as string in format: '-key value'</p>
  <p>I would like to combine multiple parameters and use the yaml template for multiple projects so this part needs to come from combination of azure variable group value and list of keys to call those values.</p>
  <p>basically I have an array:</p>
  <pre><code>[&quot;foo&quot;, &quot;bar&quot;]
  </code></pre>
  <p>and I like to convert it to string:</p>
  <pre><code>&quot;-foo fooValue -bar barValue&quot;
  </code></pre>
  <p><strong>foo</strong> and <strong>bar</strong> are keys.</p>
  <p><strong>fooValue</strong> and <strong>barValue</strong> are from variable group mapped with same keyname foo and bar.</p>
  <p>I know there is a <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#each-keyword" rel="nofollow noreferrer">Each-expression</a> in yaml, but not sure how to use it combine array to single string as variable.</p>
  <p>I've tried to make powershell script too but it doesn't return $-signs for yaml to parse later.</p>
  <p>part of yaml file:</p>
  <pre><code>parameters:
    varGroup: '' # variable group
    overrideParamKeys: [] # list of keys to put in arm. example: ['foo', 'bar'] converts to '-foo $(foo) -bar $(bar)'
  
  stages:
  
  - stage: 'deploy_${{ parameters.environment }}'
    displayName: ${{ parameters.environment }}
    variables:
    - group: '${{ parameters.varGroup }}' # use variable groupo
    - name: armOverrideParamValues
      value: ''
  
    pool:
      name: Azure Pipelines
      vmImage: 'windows-2019'
  
    jobs:  
    - job: 'setup_arm_variables'
      condition: gt(length('${{ join('', parameters.overrideParamKeys) }}'), 0)
      steps:
      - pwsh: |
          Write-Host &quot;overrideParamKeys $Env:overrideParamKeys&quot;
          function Combine-ArmOverrideKeys {
            param (
              [Parameter(Mandatory=$true)]
              [string]
              $keysString
            )
            $keys = $keysString.Split(&quot;, &quot;)
            $valString=&quot;&quot;
            foreach($key in $keys) {
              $valString += &quot; -$key \$($key)&quot;
            }
            return $valString.Trim();
          }
          $armOverrideParamValues = Combine-ArmOverrideKeys -keys $Env:overrideParamKeys
          Write-Host armOverrideParamValues $armOverrideParamValues
        displayName: &quot;Combining arm override keys to variable 'armOverrideParamValues'&quot;
        name: armOverrideParamValues
        env:
          overrideParamKeys: ${{ join(', ', parameters.overrideParamKeys) }}
  
    - job: test_variables
      steps:
      - echo: variables.armOverrideParamValues $variables.armOverrideParamValues
  
    # ...other job with task AzureResourceGroupDeployment using overrideParameters with value from variables.armOverrideParamValues
  </code></pre>