Passing VSTS Release Multi-Configuration Phase two variables, but only one multiplier

眉间皱痕 提交于 2019-12-05 17:57:28

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:

1. Specify IDs as Multipliers

2. Get the ID for each time run on the agent phase

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:

  • When run the phase A1, the variable $(IDs) value is A1;
  • When run the phase A2, the variable $(IDs) value is A2;
  • When run the phase A3, the variable $(IDs) value is A3.

3. Filter corresponding name from Names variable when each time run on the agent phase

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.

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:

  1. Set the Multipliers field to the IDs variable as Marina Liu suggested. This runs the phase once for each ID with the current ID stored in the IDs variable.
  2. Add an empty variable named CurrentName this will store the name associated with the IDs variable.

  3. 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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!