Skip to content

Commit

Permalink
[Fixes] Fix Set-EnvironmentOnAgent param mapping (#3717)
Browse files Browse the repository at this point in the history
* Update custom publishing resources

* Fix $PSModules reference in script

* Add an example for using the parameter

* fix ref in pipelines/wf/actions to use camCase variables

* Update example to use camCaps variables

* fix

* 👻
  • Loading branch information
MariusStorhaug authored Aug 26, 2023
1 parent cf6f446 commit cd33dfb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .azuredevops/pipelineTemplates/jobs.publishModule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ jobs:
. (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'pipelines' 'sharedScripts' 'Set-EnvironmentOnAgent.ps1')
# Define PS modules to install on the runner
$Modules = @(
$modules = @(
@{ Name = 'Az.Accounts' },
@{ Name = 'Az.ContainerRegistry' },
@{ Name = 'Az.Resources' }
)
# Set agent up
Set-EnvironmentOnAgent -PSModules $Modules
Set-EnvironmentOnAgent -PSModules $modules
# [Universal Artifact-feed publish] task(s)
#------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ jobs:
. (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'pipelines' 'sharedScripts' 'Set-EnvironmentOnAgent.ps1')
# Define PS modules to install on the runner
$Modules = @(
$modules = @(
@{ Name = 'Az.Accounts' },
@{ Name = 'Az.Resources' },
@{ Name = 'powershell-yaml'; Version = '0.4.2'}
)
# Additional PS modules need to be installed for the removal step in case it is enabled
if ('${{ parameters.removeDeployment}}' -eq 'true') {
$Modules += @(
$modules += @(
@{ Name = 'Az.CognitiveServices' },
@{ Name = 'Az.Compute' },
@{ Name = 'Az.KeyVault' },
Expand All @@ -112,7 +112,7 @@ jobs:
}
# Set agent up
Set-EnvironmentOnAgent -PSModules $Modules
Set-EnvironmentOnAgent -PSModules $modules
# [Agent] Replace tokens
#-----------------------
Expand Down
4 changes: 2 additions & 2 deletions .azuredevops/pipelineTemplates/jobs.validateModulePester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ jobs:
. (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'pipelines' 'sharedScripts' 'Set-EnvironmentOnAgent.ps1')
# Define PS modules to install on the runner
$Modules = @(
$modules = @(
# This is the latest tested Pester version. Uncomment the next line in case of a future breaking change in the default version installed on the runner.
# @{ Name = 'Pester'; Version = '5.3.1' }
@{ Name = 'Az.Resources' }
@{ Name = 'powershell-yaml'; Version = '0.4.2'}
)
# Set agent up
Set-EnvironmentOnAgent -PSModules $Modules
Set-EnvironmentOnAgent -PSModules $modules
# [Module Pester Test] task(s)
#-----------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ jobs:
. (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'pipelines' 'sharedScripts' 'Set-EnvironmentOnAgent.ps1')
# Define PS modules to install on the runner
$Modules = @(
$modules = @(
@{ Name = 'Az.Accounts' }
)
# Set agent up
Set-EnvironmentOnAgent -PSModules $Modules
Set-EnvironmentOnAgent -PSModules $modules
- task: AzurePowerShell@5
displayName: 'Cleanup deployments via connection [$(serviceConnection)]'
inputs:
Expand Down Expand Up @@ -96,12 +96,12 @@ jobs:
. (Join-Path '$(System.DefaultWorkingDirectory)' 'utilities' 'pipelines' 'sharedScripts' 'Set-EnvironmentOnAgent.ps1')
# Define PS modules to install on the runner
$Modules = @(
$modules = @(
@{ Name = 'Az.Accounts' }
)
# Set agent up
Set-EnvironmentOnAgent -PSModules $Modules
Set-EnvironmentOnAgent -PSModules $modules
- task: AzurePowerShell@5
displayName: 'Cleanup deployments via connection [$(serviceConnection)]'
inputs:
Expand Down
8 changes: 4 additions & 4 deletions .github/actions/templates/setEnvironment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ runs:
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'pipelines' 'sharedScripts' 'Set-EnvironmentOnAgent.ps1')
# Define PS modules to install on the runner
$Modules = @(
$modules = @(
@{ Name = 'Az.Accounts' },
@{ Name = 'Az.Resources' },
@{ Name = 'powershell-yaml'; Version = '0.4.2'}
)
# Additional PS modules need to be installed for the deployment validation removal step in case it is enabled
if (('${{ github.job}}' -eq 'job_module_deploy_validation') -and ('${{ inputs.removeDeployment}}' -eq 'true')) {
$Modules += @(
$modules += @(
@{ Name = 'Az.CognitiveServices' },
@{ Name = 'Az.Compute' },
@{ Name = 'Az.KeyVault' },
Expand All @@ -70,13 +70,13 @@ runs:
# Additional PS modules need to be installed for the publish job
if ('${{ github.job}}' -eq 'job_publish_module') {
$Modules += @(
$modules += @(
@{ Name = 'Az.ContainerRegistry' }
)
}
# Set agent up
Set-EnvironmentOnAgent -PSModules $Modules
Set-EnvironmentOnAgent -PSModules $modules
Write-Output '::endgroup::'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/platform.apiSpecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'pipelines' 'sharedScripts' 'Set-EnvironmentOnAgent.ps1')
# Define PS modules to install on the runner
$Modules = @(
$modules = @(
@{ Name = 'Az.Accounts' },
@{ Name = 'Az.Resources' }
)
# Set agent up
Set-EnvironmentOnAgent -PSModules $Modules
Set-EnvironmentOnAgent -PSModules $modules
- name: Azure Login
uses: Azure/login@v1
Expand Down
15 changes: 12 additions & 3 deletions utilities/pipelines/sharedScripts/Set-EnvironmentOnAgent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ Optional. The PowerShell modules that should be installed on the agent.
Set-EnvironmentOnAgent
Install the default PowerShell modules to configure the agent
.EXAMPLE
$modules = @(
@{ Name = 'Az.Accounts' },
@{ Name = 'Az.Resources' }
)
Set-EnvironmentOnAgent -PSModules $modules
Install the given PowerShell modules to configure the agent.
#>
function Set-EnvironmentOnAgent {

Expand Down Expand Up @@ -201,7 +210,7 @@ function Set-EnvironmentOnAgent {

$count = 1
Write-Verbose ('Try installing:') -Verbose
$modules | ForEach-Object {
$PSModules | ForEach-Object {
Write-Verbose ('- {0}. [{1}]' -f $count, $_.Name) -Verbose
$count++
}
Expand Down Expand Up @@ -238,9 +247,9 @@ function Set-EnvironmentOnAgent {

Write-Verbose ('Install-CustomModule start') -Verbose
$count = 1
Foreach ($Module in $Modules) {
Foreach ($Module in $PSModules) {
Write-Verbose ('=====================') -Verbose
Write-Verbose ('HANDLING MODULE [{0}/{1}] [{2}] ' -f $count, $Modules.Count, $Module.Name) -Verbose
Write-Verbose ('HANDLING MODULE [{0}/{1}] [{2}] ' -f $count, $PSModules.Count, $Module.Name) -Verbose
Write-Verbose ('=====================') -Verbose
# Installing New Modules and Removing Old
$null = Install-CustomModule -Module $Module -InstalledModule $installedModules
Expand Down

0 comments on commit cd33dfb

Please sign in to comment.