0

I'm trying to figure out if there is a way to pass arguments to a next line script from PowerShell array.

Ex:

$array = @('a','b','c') # This can keep increasing. 

cobertura-merge -o coverage/cobertura-coverage.xml $array[0] $array[1] $array[2]

Can someone please let me know, how to accomplish this if there are n no.of elements in the array?

Raag!

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206

1 Answers1

0

You can't store actually a complex value in variable. So you have to first join and then split it

- pwsh: |
    $val = @('a','b','c') -join ";"
    Write-Host "##vso[task.setvariable variable=paramaeters;]$val"

- pwsh: | 
    $paramaeters = '$(paramaeters)'.split(";")

    cobertura-merge -o coverage/cobertura-coverage.xml @paramaeters

Passing array should be fine as it is shown here

Please be awate that it will work if you do both steps inside the same job. Otherwise you need yo use output variables.

Please change $parameter to @parameters to use splatting arrays

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107