I am trying to create an Azure Pipeline. But I am having a problem looping an Azure task in it. I have explained below through a simplified example the problem I am facing.
I hope to create multiple Azure web apps through this pipeline. Each webapp has a command passed to it using --startup-file
and this command includes an argument. The number of apps to create and the argument to pass to each one, is provided as a runtime parameter when triggering the pipeline
E.g.
If NUMBER=3 and ARGUMENTS=24,56,123
then each Azure web app --name
and --startup-file
should be as follows
--name myapp-1 --startup-file 'java -jar my.jar --arg 24
--name myapp-2 --startup-file 'java -jar my.jar --arg 56
--name myapp-3 --startup-file 'java -jar my.jar --arg 123
The pipeline prompts the user for the number of web apps to create and a comma separated string of arguments to pass to them. An Azure pipeline step defined in main.yaml
passes these two parameters to a template (createapps.yaml
). Then based on this template the defined number of apps must be created.
main.yaml is as follows
parameters:
- name: NUMBER
type: number
- name: ARGUMENTS
type: string
steps:
- template: createapps.yaml
parameters:
NUMBER: ${{ parameters.NUMBER }}
ARGUMENTS: ${{ parameters.ARGUMENTS }}
createapps.yaml is as follows
parameters:
- name: NUMBER
type: number
- name: ARGUMENTS
type: string
steps:
- task: AzureCLI@2
displayName: Create Apps
az webapp create \
--name myapp-<Number> \
--plan myplan \
--resource-group myrg \
--deployment-container-image-name myimage:latest \
--startup-file 'java -jar my.jar --arg <Argument>'
How can I loop the task in createapps.yaml
and assign <Number> and <Argument> in the Azure CLI command by iterating NUMBER
and ARGUMENTS
?