0
votes

I have an Azure release pipeline that I am using for a Windows Virtual Desktop deployment.

I have created a simple Powershell task to obtain some information about the existing session hosts available and capture it to a list which I have then set to a dynamic variable using

$sessions = "vm_name1 vm_name2 vm_name3"    
write-host "##vso[task.setvariable variable=sessions;isOutput=true;]$sessions"

I can then retrieve this fine in later tasks by using

write-host $(taskreference.sessions)
result: vm_name1 vm_name2 vm_name3

However, I need to access be able to parse this variable $(sessions) to obtain the individual host names to be used in later steps of my release pipeline.

i.e. $vms = $(sessions).Split(" ")
$vms[0]
$vms[1]
etc etc 

I have tried various methods to access and expand this variable but ultimately am struggling to get anything working as it will always return null. When using a Azure CLI task, I am able to successfully access the variable using the exact same code. I suspect this is something to do with how the tasks work during run time/compile time.

Is there any way that I could parse the variable properly to obtain the individual host names?

1
Does $vms = $(taskreference.sessions) -split '\s+' not work?Theo
I've just tested this but unfortunately it doesn't work as $vms still returns null. I forgot to mention that I have enabled debug mode in DevOps and can see that when I cast the variable into another variable i.e $var = $vms it does show that both $vms and $var is equal to vm_name1 vm_name2 vm_name3 in debug. But if I do write-host $var in the actual code, it returns null.m00shii

1 Answers

0
votes

The one you described would work fine if the variable is passed in as a string parameter.

Else this might work.

$vms = "$(sessions)".Split(" ")
$vms[0]
$vms[1]