I have a scheduled yaml pipeline. 2 Tasks to execute.1st task is to create a hashtable which is combination of subscription and array of resourcegroups. 2nd Task is to call another template using one subscription and one rg from 1st task. Code is mentioned below.
steps:
- task: AzurePowerShell@5
displayName:
condition: succeeded()
inputs:
azureSubscription: '$(AzureSubscription)'
ScriptType: 'InlineScript'
Inline: |
$Subscriptions = Get-AzSubscription
$AKSSubscriptionAndRG = @{}
foreach ($Subscription in $Subscriptions) {
Set-AzContext -SubscriptionName $Subscription
$AKSResourceGroup = (Get-AzResource -ResourceType "Microsoft.ContainerService/managedClusters").ResourceGroupName
if(![String]::IsNullOrWhiteSpace($AKSResourceGroup)){
$AKSSubscriptionAndRG.add($Subscription.Name,$AKSResourceGroup)
}
}
Write-Output "Exporting pipeline variable AKSSubscription with value AKSRG"
Write-Output "##vso[task.setvariable variable=AKSSubscriptionAndRG;]$AKSSubscriptionAndRG"
azurePowerShellVersion: 'LatestVersion'
FailOnStandardError: true
- template: another.yaml
parameters:
AzureSubscription: '$(AzureSubscription)'
AksResourceGroupName: '$(AksResourceGroupName)'
My question is : How to pass each subscription and RG to the 2nd template? Can someone help me?