tasks/publishing.tasks.ps1
# Synopsis: Publish Bicep modules task PublishBicepModules GitVersion,{ # validate publish details if (!$BicepRegistryFqdn) { throw "The 'BicepRegistryFqdn' variables has not been defined" } elseif (!$BicepRegistryFqdn.EndsWith(".azurecr.io")) { throw "The 'BicepRegistryFqdn' must point to an Azure Container Registry with the '.azurecr.io' suffix - current value: $BicepRegistryFqdn" } # Publishing Bicep modules requires a logged-in Azure-Cli session if (!(Test-AzCliConnection)) { throw "You must be logged-in to azure-cli to publish Bicep modules to a private registry" } if (!$BaseRegistryPath) { $BaseRegistryPath = "bicep/modules" } if (!$BicepModuleVersionTag) { $BicepModuleVersionTag = ($script:GitVersion).SemVer } $filesToPublish = Get-ChildItem -Recurse -Filter *.bicep -Path ./modules $failBuild = $false foreach ($file in $filesToPublish) { $registryTargetPath = "br:{0}/{1}/{2}:{3}" -f ` $BicepRegistryFqdn, $BaseRegistryPath, [IO.Path]::GetFileNameWithoutExtension($file), $BicepModuleVersionTag Write-Build White "Publishing $file -> $registryTargetPath" & az bicep publish -f $file -t $registryTargetPath if ($LASTEXITCODE -ne 0) { $failBuild = $true } } if ($failBuild) { throw "Bicep publish error(s) - check preceeding log messages" } else { Write-Build Green "Bicep module published OK" } } |