From 28a6d0f174018574afb4309c25ee4c27bfa6631b Mon Sep 17 00:00:00 2001 From: SeSeicht Date: Tue, 26 Apr 2022 15:45:18 +0200 Subject: [PATCH 1/3] change Task from PS to AzureCLI --- .../pipelineTemplates/jobs.publishModule.yml | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/.azuredevops/pipelineTemplates/jobs.publishModule.yml b/.azuredevops/pipelineTemplates/jobs.publishModule.yml index 296ec2ceb2..03eee6b796 100644 --- a/.azuredevops/pipelineTemplates/jobs.publishModule.yml +++ b/.azuredevops/pipelineTemplates/jobs.publishModule.yml @@ -253,22 +253,21 @@ jobs: Write-Host "##[endgroup]" } - # [private bicep registry publish] task(s) - #------------------------------------------- - - task: AzurePowerShell@5 + - task: AzureCLI@2 displayName: 'Publish module to private bicep registry' condition: and( eq(variables['bicepRegistryDoPublish'], true), succeeded() ) - enabled: true inputs: + addSpnToEnvironment: true azureSubscription: '${{ parameters.serviceConnection }}' - azurePowerShellVersion: ${{ parameters.azurePowerShellVersion }} - preferredAzurePowerShellVersion: ${{ parameters.preferredAzurePowerShellVersion }} - pwsh: true - ScriptType: InlineScript - inline: | + scriptType: pscore + scriptLocation: inlineScript + inlineScript: | + $SecuredPassword = ConvertTo-SecureString -AsPlainText -String $env:servicePrincipalKey + $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $env:servicePrincipalId, $SecuredPassword + Connect-AzAccount -ServicePrincipal -TenantId $env:tenantId -Credential $Credential # Load used functions . (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Get-ModulesToPublish.ps1') . (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Publish-ModuleToPrivateBicepRegistry.ps1') @@ -295,11 +294,11 @@ jobs: Write-Host "##[group]$(' - [{0}] [{1}]' -f $RelPath, $ModuleToPublish.Version)" $functionInput = @{ - TemplateFilePath = $ModuleToPublish.TemplateFilePath + TemplateFilePath = $ModuleToPublish.TemplateFilePath BicepRegistryName = '${{ parameters.bicepRegistryName }}' BicepRegistryRgName = '${{ parameters.bicepRegistryRgName }}' BicepRegistryRgLocation = '${{ parameters.bicepRegistryRgLocation }}' - ModuleVersion = $ModuleToPublish.Version + ModuleVersion = $ModuleToPublish.Version } Write-Verbose "Invoke Publish-ModuleToPrivateBicepRegistry with" -Verbose @@ -307,4 +306,4 @@ jobs: Publish-ModuleToPrivateBicepRegistry @functionInput -Verbose Write-Host "##[endgroup]" - } + } \ No newline at end of file From aa1e904dc02095f729ca85b65c2a778ed4950944 Mon Sep 17 00:00:00 2001 From: SeSeicht Date: Tue, 26 Apr 2022 16:06:46 +0200 Subject: [PATCH 2/3] add comment again --- .azuredevops/pipelineTemplates/jobs.publishModule.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.azuredevops/pipelineTemplates/jobs.publishModule.yml b/.azuredevops/pipelineTemplates/jobs.publishModule.yml index 03eee6b796..a2525f5636 100644 --- a/.azuredevops/pipelineTemplates/jobs.publishModule.yml +++ b/.azuredevops/pipelineTemplates/jobs.publishModule.yml @@ -253,6 +253,8 @@ jobs: Write-Host "##[endgroup]" } + # [private bicep registry publish] task(s) + #------------------------------------------- - task: AzureCLI@2 displayName: 'Publish module to private bicep registry' condition: and( From 053c99037af2b878b4cb9a6f33d338a80957db77 Mon Sep 17 00:00:00 2001 From: SeSeicht <48480298+SeSeicht@users.noreply.github.com> Date: Fri, 29 Apr 2022 11:59:30 +0200 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Alexander Sehr --- .azuredevops/pipelineTemplates/jobs.publishModule.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.azuredevops/pipelineTemplates/jobs.publishModule.yml b/.azuredevops/pipelineTemplates/jobs.publishModule.yml index a2525f5636..b4b6db816c 100644 --- a/.azuredevops/pipelineTemplates/jobs.publishModule.yml +++ b/.azuredevops/pipelineTemplates/jobs.publishModule.yml @@ -267,9 +267,11 @@ jobs: scriptType: pscore scriptLocation: inlineScript inlineScript: | + # Log into Az-PowerShell context $SecuredPassword = ConvertTo-SecureString -AsPlainText -String $env:servicePrincipalKey $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $env:servicePrincipalId, $SecuredPassword Connect-AzAccount -ServicePrincipal -TenantId $env:tenantId -Credential $Credential + # Load used functions . (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Get-ModulesToPublish.ps1') . (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Publish-ModuleToPrivateBicepRegistry.ps1')