1

I came across a scenario, where I need to create an Array variable or a list. The values which I am expecting are of type String

I am getting those individual values inside the loop (Variable1 in the below code). I want to set those values as a variable (arrayVariable in the below code) so that I can use those values in different tasks or templates.

variables:
  - name: arrayVariable
    value:

steps:

- powershell: |
      ## Some Other Conditional Code 
      For ($i=0; $i -lt $temp.Length; $i++)
      {
         $Variable1=$temp[$i]
         echo "this is $Variable1 value" ## Here I can have multiple values on the basis of loop
         
         ## This value i want to keep in Array or in List to reffer it another task/templates.
         
         Write-Host "##vso[task.setvariable variable=arrayVariable]$Variable1"
         echo "Variable's value in loop  $Variable1"
      }
  displayName: 'Powershell Task'

Please let me know if the creation of the list or array is possible at runtime.

Any Help | Guidance will be appreciable.

Eddie
  • 501
  • 1
  • 10
  • 19
  • Hi Eddie, Maybe you could save the variable in the json file and then refer to this [ticket](https://stackoverflow.com/questions/59965101/azure-pipelines-add-new-element-in-json-array-vsts-pipelines-appsettings-json) to add new variables. – Vito Liu May 28 '21 at 12:33
  • This is not quite possible out of the box (unfortunately), but there is a workaround check this out: https://stackoverflow.com/questions/67483194/pass-array-of-files-into-the-parameter-of-awscli1-task/67498247#67498247 – Bruno May 30 '21 at 23:20
  • @VitoLiu : Thanks I have checked that But, It doesn't work in my case – Eddie May 31 '21 at 05:20
  • @Bruno : Thanks for the clarification. on line `echo "Variable's value in loop $Variable1"` I am getting the required value. I just want to copy that in the array or in list. If its possible – Eddie May 31 '21 at 05:22
  • As I mentioned, variables in Azure Pipelines don't support Arrays or lists, therefore what you wanna do it's just not possible, but you can workaround it. – Bruno May 31 '21 at 10:57

0 Answers0