From 65f1911733afd2a61bdbc4175058c808d4e9830c Mon Sep 17 00:00:00 2001 From: sebastian claesson Date: Fri, 15 Mar 2024 16:44:19 +0100 Subject: [PATCH] adding pre-initialize task --- .pipelines/pull.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.pipelines/pull.yml b/.pipelines/pull.yml index afad219b..96ba5f04 100644 --- a/.pipelines/pull.yml +++ b/.pipelines/pull.yml @@ -149,6 +149,29 @@ jobs: script: | git checkout -b $(branch) + # + # Verify that the Management resource provider is registered in the subscription where AzOps will initialize. + # + + - task: PowerShell@2 + displayName: "Pre-initialize" + inputs: + targetType: "inline" + script: | + $Env:PSModulePath = $Env:PSModulePath, '$(modulesFolder)' -join [IO.Path]::PathSeparator + $ManagementResourceProvider = Get-AzResourceProvider -ProviderNamespace 'microsoft.management' | Where-object {$_.ResourceTypes.ResourceTypeName -eq 'managementGroups'} + $InitSub = $((Get-AzContext).Subscription.Id) + if ($ManagementResourceProvider.RegistrationState -ne 'Registered') { + Write-verbose "The Azure Resource Provider 'Microsoft.Management' is not currently registered in the subscription '$InitSub'" -Verbose + try { + Write-verbose "Attempting to register the 'Microsoft.Management' Resource provider." -Verbose + Register-AzResourceProvider -ProviderNamespace 'Microsoft.Management' + } catch { + Write-Warning "Unable to register the 'Microsoft.Management' resource provider for subscription '$InitSub'" + throw + } + } + # # Initialize # Generate new state data