I have a VSTS Release Definition that is passed two variables, the contents of which I do not control. They contain a comma separated string of Names and a comma separated string of IDs which correspond to the Names by index.
I want to use an agent phase configured with the parallelism option set to multi-configuration and the multiplier field set to the string of IDs, so the phase is run once for each ID. I also want to use the name that corresponds to the ID in that phase, but I'm not sure how to do this.
If I set the multiplier to both variables (ID and Name) it runs the phase for the Cartesian product (cross join) of the two arrays which is not desired.
Example:
IDs: "A1, A2, A3"
Names: "Anna, Adam, Abby"
Runs the phase 9 times: "A1" & "Anna", "A2" & "Anna", "A3" & "Anna"
"A1" & "Adam", "A2" & "Adam", "A3" & "Adam"
"A1" & "Abby", "A2" & "Abby", "A3" & "Abby"
If I set the multiplier to the ID variable only it runs the phase the correct number of times, but I can't figure out how to pass the corresponding name into the phase.
Is this even possible?
Thanks in advance!
To make the multi-configuration phase run once for each item in the IDs
variable, and make the both the current ID and name available for use in the phase:
IDs
variable as Marina Liu suggested. This runs the phase once for each ID
with the current ID
stored in the IDs
variable.Add an empty variable named CurrentName
this will store the name associated with the IDs
variable.
Add an inline Powershell script task into the Agent Phase containing the following commands:
$names = "$(Names)".Split(", ",[System.StringSplitOptions]::RemoveEmptyEntries)
Write-Host "##vso[task.setvariable variable=CurrentName]$($names[[int]"$(SYSTEM.JOBPOSITIONINPHASE)" - 1])"
The script uses the built in System.JobPositionInPhase
variable, which contains the index of the phase currently being run, to get the name for the current phase for the from the Names
variable and stores it in the CurrentName
variable.
You can use $(CurrentName)
anywhere in the phase to get the value of the name associated with $(IDs)
.
If you want to run the phase for three times (A1-Anna
, A2-Adam
and A3-Abby
), you just need to specify one variable (no matter for variable IDs or Names) as Multipliers and filter the corresponding item from the other variable.
Such as use variable IDs
as Multipliers and filter corresponding name from variable Names
each time, you can use below steps:
After specifying variable IDs
as Multipliers, the agent will run three times: A1
, A2
and A3
.
And you can get relate ID by variable $(IDs)
when run on the agent phase each time:
A1
, the variable $(IDs)
value is A1
;A2
, the variable $(IDs)
value is A2
;A3
, the variable $(IDs)
value is A3
.Since you can get the ID for each time to run, you can get corresponding name with the ID by some defined rules. Such as use if condition to get the correct name, or parse ID's index and get the corresponding name etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With