Reputation: 189
I am aware of how to use for each loop and did POC and it is working fine. But I have a request where I need to use For loop instead of For each.
Business case: Need to create task dynamically based on user input. Reason: Some teams uses Multiple maven task in their projects. I have a centralised Template which will create task based on user input for the no. of maven they need in their pipeline.
Example ${{for i=1; i<= n; i++}} -task: maven@5 pompath: ${pomxmlpath}
When n = 5 it has to create 5 maven task in the azure pipeline.
Upvotes: 5
Views: 5528
Reputation: 51183
There is no such For loop
expression in Azure YAML pipeline. And actually loop through dynamic template parameters in Azure devops YAML by specify n in the runtime is also not available.
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://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops
Upvotes: 1