传递VSTS Release Multi-Configuration Phase两个变量,但只有一个乘数 [英] Passing VSTS Release Multi-Configuration Phase two variables, but only one multiplier

查看:32
本文介绍了传递VSTS Release Multi-Configuration Phase两个变量,但只有一个乘数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VSTS版本定义,该定义传递了两个变量,这些变量的内容我不控制.它们包含一个逗号分隔的Names字符串和一个ID逗号分隔的ID字符串,这些ID对应于按索引显示的Names.

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.

我想使用一个代理阶段,该阶段配置了将并行性选项设置为多配置,并将乘数字段设置为ID字符串,因此该阶段对于每个ID运行一次.我还想在该阶段使用与ID对应的名称,但是我不确定如何执行此操作.

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.

如果将乘数设置为两个变量(ID和名称),则将运行两个数组的笛卡尔积(交叉连接)的阶段,这是不希望的.

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.

示例:

                    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"

如果我将乘数设置为ID变量,那么它只能以正确的次数运行该阶段,但是我不知道如何将相应的名称传递到该阶段.

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.

这有可能吗?

提前谢谢!

推荐答案

要使多配置阶段对IDs变量中的每个项目运行一次,并使当前ID和名称都可用于阶段:

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. 按照Marina Marina的建议,将乘数"字段设置为IDs变量.这样,每个ID都会运行一次该阶段,而当前ID会存储在IDs变量中.
  2. 添加一个名为CurrentName的空变量,该变量将存储与IDs变量关联的名称.

  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.

将内联Powershell脚本任务添加到包含以下命令的代理阶段:

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])"

$names = "$(Names)".Split(", ",[System.StringSplitOptions]::RemoveEmptyEntries) Write-Host "##vso[task.setvariable variable=CurrentName]$($names[[int]"$(SYSTEM.JOBPOSITIONINPHASE)" - 1])"

脚本使用内置的System.JobPositionInPhase变量(包含当前正在运行的阶段的索引)从Names变量获取的当前阶段的名称,并将其存储在CurrentName变量中

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.

您可以在阶段中的任何地方使用$(CurrentName)来获取与$(IDs)关联的名称的值.

You can use $(CurrentName) anywhere in the phase to get the value of the name associated with $(IDs).

这篇关于传递VSTS Release Multi-Configuration Phase两个变量,但只有一个乘数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆