Skip to content

Commit

Permalink
Added context setting (#3882)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSehr authored Aug 31, 2023
1 parent f08a6e5 commit b163f0a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .azuredevops/pipelineTemplates/jobs.publishModule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ parameters:
vmImage: '$(vmImage)'
defaultJobTimeoutInMinutes: 120
modulesRepository: '$(modulesRepository)'
subscriptionId: '$(ARM_SUBSCRIPTION_ID)'

# Logic-related parameters
## Module-related
Expand Down Expand Up @@ -220,6 +221,10 @@ jobs:
pwsh: true
ScriptType: InlineScript
inline: |
# Set context to chosen subscription
Write-Verbose ('Setting context to subscription [{0}]' -f '${{ parameters.subscriptionId }}') -Verbose
$null = Set-AzContext -Subscription '${{ parameters.subscriptionId }}'
# Load used functions
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Get-ModulesToPublish.ps1')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Get-ModulesMissingFromTemplateSpecsRG.ps1')
Expand Down Expand Up @@ -311,6 +316,10 @@ jobs:
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $env:servicePrincipalId, $SecuredPassword
$null = Connect-AzAccount -ServicePrincipal -TenantId $env:tenantId -Credential $Credential
# Set context to chosen subscription
Write-Verbose ('Setting context to subscription [{0}]' -f '${{ parameters.subscriptionId }}') -Verbose
$null = Set-AzContext -Subscription '${{ parameters.subscriptionId }}'
# Load used functions
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Get-ModulesToPublish.ps1')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(pipelineFunctionsPath)' 'resourcePublish' 'Get-ModulesMissingFromPrivateBicepRegistry.ps1')
Expand Down
14 changes: 14 additions & 0 deletions .github/actions/templates/publishModule/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
## | Parameter | Required | Default | Description | Example |
## |--------------------------|----------|---------|--------------------------------------------------------------------------------------------------|--------------------------------------------------------|
## | templateFilePath | true | '' | The path to the template file to publish | 'modules/api-management/service/main.bicep' |
## | subscriptionId | false | '' | The ID of the subscription to publish to | '11111111-1111-1111-1111-111111111111' |
## | templateSpecsRgName | false | '' | Required to publish to template spec. ResourceGroup of the template spec to publish to | 'artifacts-rg' |
## | templateSpecsRgLocation | false | '' | Required to publish to template spec. Location of the template spec resource group | 'WestEurope' |
## | templateSpecsDescription | false | '' | Required to publish to template spec. Description of the template spec to publish to | 'This is an API-Management service template' |
Expand All @@ -35,6 +36,9 @@ inputs:
templateFilePath:
description: 'The path to the template file to publish'
required: true
subscriptionId:
description: 'The ID of the subscription to publish to'
required: false
templateSpecsRgName:
description: 'Required to publish to template spec. ResourceGroup of the template spec to publish to'
required: false
Expand Down Expand Up @@ -84,6 +88,11 @@ runs:
# Grouping task logs
Write-Output '::group::Publish module to template specs'
if (-not [String]::IsNullOrEmpty('${{ inputs.subscriptionId }}')) {
Write-Verbose ('Setting context to subscription [{0}]' -f '${{ inputs.subscriptionId }}') -Verbose
$null = Set-AzContext -Subscription '${{ inputs.subscriptionId }}'
}
# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'pipelines' 'resourcePublish' 'Get-ModulesToPublish.ps1')
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'pipelines' 'resourcePublish' 'Get-ModulesMissingFromTemplateSpecsRG.ps1')
Expand Down Expand Up @@ -159,6 +168,11 @@ runs:
# Grouping task logs
Write-Output '::group::Publish module to private bicep registry'
if (-not [String]::IsNullOrEmpty('${{ inputs.subscriptionId }}')) {
Write-Verbose ('Setting context to subscription [{0}]' -f '${{ inputs.subscriptionId }}') -Verbose
$null = Set-AzContext -Subscription '${{ inputs.subscriptionId }}'
}
# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'pipelines' 'resourcePublish' 'Get-ModulesToPublish.ps1')
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'pipelines' 'resourcePublish' 'Get-ModulesMissingFromPrivateBicepRegistry.ps1')
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/templates/validateModuleDeployment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ runs:
ManagementGroupId = '${{ inputs.managementGroupId }}'
}
if (-not [String]::IsNullOrEmpty('${{ inputs.subscriptionId }}')) {
$functionInput['SubscriptionId'] = '${{ inputs.subscriptionId }}'
}
Write-Verbose 'Invoke task with' -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/template.module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ jobs:
uses: ./.github/actions/templates/publishModule
with:
templateFilePath: '${{ inputs.modulePath }}/main.bicep'
subscriptionId: '${{ secrets.ARM_SUBSCRIPTION_ID }}'
templateSpecsRGName: '${{ env.templateSpecsRGName }}'
templateSpecsRGLocation: '${{ env.templateSpecsRGLocation }}'
templateSpecsDescription: '${{ env.templateSpecsDescription }}'
Expand Down

0 comments on commit b163f0a

Please sign in to comment.