From 538796f7d5f44ea4ab458a592d583c4d0766a274 Mon Sep 17 00:00:00 2001 From: Nathan Wright Date: Mon, 10 Nov 2025 13:12:17 -0800 Subject: [PATCH 1/2] Use AWS.Tools.* Powershell Modules for AWSPowershellModuleScript if available --- ...-164328cf-e5ba-44d0-9133-9e00214d1af9.json | 4 ++ .../RunAWSPowerShellModuleScript.ps1 | 52 ++++++++++++------- src/tasks/AWSPowerShellModuleScript/task.json | 2 + 3 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 .changes/next-release/Breaking Change-164328cf-e5ba-44d0-9133-9e00214d1af9.json diff --git a/.changes/next-release/Breaking Change-164328cf-e5ba-44d0-9133-9e00214d1af9.json b/.changes/next-release/Breaking Change-164328cf-e5ba-44d0-9133-9e00214d1af9.json new file mode 100644 index 00000000..34a6f744 --- /dev/null +++ b/.changes/next-release/Breaking Change-164328cf-e5ba-44d0-9133-9e00214d1af9.json @@ -0,0 +1,4 @@ +{ + "type": "Breaking Change", + "description": "Use AWS.Tools.* Powershell Modules for AWSPowershellModuleScript if available" +} \ No newline at end of file diff --git a/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 b/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 index 764df925..6a9eb306 100644 --- a/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 +++ b/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 @@ -33,31 +33,43 @@ try { Assert-VstsPath -LiteralPath $tempDirectory -PathType 'Container' - # install the module if not present (we assume if present it is an an autoload-capable - # location) + # Check for modular AWS powershell module first Write-Host (Get-VstsLocString -Key 'TestingAWSModuleInstalled') - if (!(Get-Module -Name AWSPowerShell -ListAvailable)) { - Write-Host (Get-VstsLocString -Key 'AWSModuleNotFound') - - # AllowClobber is not available in Install-Module in the Hosted agent (but is in the - # Hosted 2017 agent). We always install/update the latest NuGet package - # provider to work around Install-Module on the Hosted agent also not having -Force and - # producing the error - # - # 'Exception calling “ShouldContinue” with “2” argument(s): “Windows PowerShell is in NonInteractive mode.' - # - Write-Host (Get-VstsLocString -Key 'InstallingAWSModule') - Install-PackageProvider -Name NuGet -Scope CurrentUser -Verbose -Force - $installModuleCmd = Get-Command Install-Module - if ($installModuleCmd.Parameters.ContainsKey("AllowClobber")) { - Install-Module -Name AWSPowerShell -Scope CurrentUser -Verbose -AllowClobber -Force + if (Get-Module -Name AWS.Tools.Common -ListAvailable) { + Write-Host (Get-VstsLocString -Key 'ModularAWSModuleFound') + if((Get-Module -Name AWS.Tools.SecurityToken -ListAvailable)) { + Import-Module AWS.Tools.SecurityToken } else { - Install-Module -Name AWSPowerShell -Scope CurrentUser -Verbose -Force + Write-Host (Get-VstsLocString -Key 'SecurityTokenModuleNotFound') } } - - Import-Module -Name AWSPowerShell + else { + # install the module if not present (we assume if present it is an an autoload-capable + # location) + if (!(Get-Module -Name AWSPowerShell -ListAvailable)) { + Write-Host (Get-VstsLocString -Key 'AWSModuleNotFound') + + # AllowClobber is not available in Install-Module in the Hosted agent (but is in the + # Hosted 2017 agent). We always install/update the latest NuGet package + # provider to work around Install-Module on the Hosted agent also not having -Force and + # producing the error + # + # 'Exception calling “ShouldContinue” with “2” argument(s): “Windows PowerShell is in NonInteractive mode.' + # + Write-Host (Get-VstsLocString -Key 'InstallingAWSModule') + Install-PackageProvider -Name NuGet -Scope CurrentUser -Verbose -Force + $installModuleCmd = Get-Command Install-Module + if ($installModuleCmd.Parameters.ContainsKey("AllowClobber")) { + Install-Module -Name AWSPowerShell -Scope CurrentUser -Verbose -AllowClobber -Force + } + else { + Install-Module -Name AWSPowerShell -Scope CurrentUser -Verbose -Force + } + } + + Import-Module -Name AWSPowerShell + } ############################################################################### # If credentials and/or region are not defined on the task we assume them to be diff --git a/src/tasks/AWSPowerShellModuleScript/task.json b/src/tasks/AWSPowerShellModuleScript/task.json index 143e879f..6eedee4c 100644 --- a/src/tasks/AWSPowerShellModuleScript/task.json +++ b/src/tasks/AWSPowerShellModuleScript/task.json @@ -132,6 +132,8 @@ "messages": { "GeneratingScript": "Generating script.", "TestingAWSModuleInstalled": "Checking install status for AWS Tools for Windows PowerShell module.", + "ModularAWSModuleFound": "AWS.Tools.Common found. Assuming all needed AWS.Tools modules are already installed.", + "SecurityTokenModuleNotFound": "AWS.Tools.SecurityToken module not found. You will not be able to use a service connection specifying a role ARN.", "AWSModuleNotFound": "AWS Tools for Windows PowerShell module not found.", "InstallingAWSModule": "Installing AWS Tools for Windows PowerShell module to current user scope", "ConfiguringRegionFromTaskConfiguration": "Region discovered from task configuration", From d7dc4c3d699d73f89238e34a04918af8cc09c698 Mon Sep 17 00:00:00 2001 From: Nathan Wright Date: Mon, 10 Nov 2025 13:48:02 -0800 Subject: [PATCH 2/2] cleanup --- .../RunAWSPowerShellModuleScript.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 b/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 index 6a9eb306..af3acbb0 100644 --- a/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 +++ b/src/tasks/AWSPowerShellModuleScript/RunAWSPowerShellModuleScript.ps1 @@ -37,8 +37,8 @@ try { Write-Host (Get-VstsLocString -Key 'TestingAWSModuleInstalled') if (Get-Module -Name AWS.Tools.Common -ListAvailable) { Write-Host (Get-VstsLocString -Key 'ModularAWSModuleFound') - if((Get-Module -Name AWS.Tools.SecurityToken -ListAvailable)) { - Import-Module AWS.Tools.SecurityToken + if(Get-Module -Name AWS.Tools.SecurityToken -ListAvailable) { + Import-Module -Name AWS.Tools.SecurityToken } else { Write-Host (Get-VstsLocString -Key 'SecurityTokenModuleNotFound')