需要为 Azure 管道模板 yaml 中的每个循环使用 For 循环
Need to use For loop not for each loop in Azure Pipeline Template yaml
我知道如何使用每个循环并进行了 POC,并且工作正常。但是我有一个请求,我需要使用 For 循环而不是 For each。
业务案例:需要根据用户输入动态创建任务。
原因:一些团队在他们的项目中使用了多个maven任务。我有一个集中式模板,它将根据用户输入的号码创建任务。他们在管道中需要的 Maven。
例子
${{对于 i=1;我<= n;我++}}
-任务:maven@5
pompath: ${pomxmlpath}
当 n = 5 时,它必须在 azure 管道中创建 5 个 maven 任务。
Azure YAML 管道中没有这样的 For loop
表达式。实际上通过在运行时指定 n 在 Azure devops YAML 中循环动态模板参数也是不可用的。
Within a template expression, you have access to the parameters context that contains the values of parameters passed in. Additionally, you have access to the variables context that contains all the variables specified in the YAML file plus the system
variables. Importantly, it doesn't have runtime variables such as those stored on the pipeline or given when you start a run. Template expansion happens very early in the run, so those variables aren't available.
https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops
我知道如何使用每个循环并进行了 POC,并且工作正常。但是我有一个请求,我需要使用 For 循环而不是 For each。
业务案例:需要根据用户输入动态创建任务。 原因:一些团队在他们的项目中使用了多个maven任务。我有一个集中式模板,它将根据用户输入的号码创建任务。他们在管道中需要的 Maven。
例子 ${{对于 i=1;我<= n;我++}} -任务:maven@5 pompath: ${pomxmlpath}
当 n = 5 时,它必须在 azure 管道中创建 5 个 maven 任务。
Azure YAML 管道中没有这样的 For loop
表达式。实际上通过在运行时指定 n 在 Azure devops YAML 中循环动态模板参数也是不可用的。
Within a template expression, you have access to the parameters context that contains the values of parameters passed in. Additionally, you have access to the variables context that contains all the variables specified in the YAML file plus the system variables. Importantly, it doesn't have runtime variables such as those stored on the pipeline or given when you start a run. Template expansion happens very early in the run, so those variables aren't available.
https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops