About: 2 x Microsoft MVP - IaC & Devops | 2 x Sessionize Active Speaker | Blogger ✍️ | Public Speaker 🔊 | Long Distance Runner🏃♂️ | Hiking 🥾 | Traveler 🧳 | Citizen of the 🌎
Location:
Ennetbaden, Switzerland
Joined:
Mar 10, 2022
The Art of Iteration: Starting the Cycle
Publish Date: Jan 3
2 0
Greetings my fellow Technology Advocates and Specialists.
This is the Chapter #1 of my Mastering Loops in Azure DevOps Series.
In this Session, I will walk you through The Art of Iteration: Starting the Cycle.
This is a quick start guide to introduce the topic and how it is relevant to the real world.
IMPORTANT NOTE:-
The YAML Pipeline is tested on WINDOWS BUILD AGENT Only!!!
REQUIREMENTS:-
Azure Subscription.
Azure DevOps Organisation and Project.
Service Principal with Required RBAC (Contributor) applied on Subscription or Resource Group(s).
Azure Resource Manager Service Connection in Azure DevOps.
I.) Declare "Parameter" of type "Object". In this example, I have declared 3 values (Resource Group Names) as an array.
######################
#DECLARE PARAMETERS:-
######################
parameters:
- name: RGNAME
displayName: Please Provide the Resource Group Name:-
type: object
default: [AMRG001,AMRG002,AMRG003]
II.) Declare "Each" at beginning of the Pipeline stage. The "rg" variable stores all the values that the "each" keyword iterates over in the parameter of type object.
stages:
- ${{ each rg in parameters.RGNAME }}:
III.) As there are 3 values declared in "Parameter" of type "Object", there will be 3 STAGES CREATED.
IV.) Name of each stage will be one of iterated value from the array declared in "Parameter" of type "Object".
- stage: CREATE_${{ rg }}
V.) Finally, each stage displays the Value in the console.
steps:
- script: echo "Creating "${{ rg }}""
OUTPUT OF EXAMPLE:-
1. As in the example, there were 3 values declared in "Parameter" of type "Object", hence 3 STAGES got created.
2. Name of each stage is the iterated value from the array declared in "Parameter" of type "Object".