diff --git a/Tasks/AzureFileCopyV4/AzureFileCopy.ps1 b/Tasks/AzureFileCopyV4/AzureFileCopy.ps1 index 463e00c57d46..e70099392c19 100644 --- a/Tasks/AzureFileCopyV4/AzureFileCopy.ps1 +++ b/Tasks/AzureFileCopyV4/AzureFileCopy.ps1 @@ -63,6 +63,10 @@ Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ $endpoint = Get-VstsEndpoint -Name $connectedServiceName -Require +# Update PSModulePath for hosted agent +. "$PSScriptRoot\Utility.ps1" +CleanUp-PSModulePathForHostedAgent + if (Get-Module Az.Accounts -ListAvailable){ Initialize-AzModule -Endpoint $endpoint } @@ -75,7 +79,6 @@ Import-VstsLocStrings -LiteralPath $PSScriptRoot/Task.json # Load all dependent files for execution . "$PSScriptRoot\AzureFileCopyRemoteJob.ps1" -. "$PSScriptRoot\Utility.ps1" # Enabling detailed logging only when system.debug is true $enableDetailedLogging = ($env:system_debug -eq "true") diff --git a/Tasks/AzureFileCopyV4/Utility.ps1 b/Tasks/AzureFileCopyV4/Utility.ps1 index 732c350d169f..e83a6a65fff9 100644 --- a/Tasks/AzureFileCopyV4/Utility.ps1 +++ b/Tasks/AzureFileCopyV4/Utility.ps1 @@ -1301,4 +1301,30 @@ function Get-InvokeRemoteScriptParameters protocol = $protocol; sessionOption = $sessionOption } +} + +function CleanUp-PSModulePathForHostedAgent { + # Clean up PSModulePath for hosted agent + $azureRMModulePath = "C:\Modules\azurerm_2.1.0" + $azureModulePath = "C:\Modules\azure_2.1.0" + $newEnvPSModulePath = $env:PSModulePath + + if ($newEnvPSModulePath.split(";") -contains $azureRMModulePath) { + $newEnvPSModulePath = (($newEnvPSModulePath).Split(";") | ? { $_ -ne $azureRMModulePath }) -join ";" + write-verbose "$azureRMModulePath removed. Restart the prompt for the changes to take effect." + } + else { + write-verbose "$azureRMModulePath is not present in $newEnvPSModulePath" + } + + if ($newEnvPSModulePath.split(";") -contains $azureModulePath) { + $newEnvPSModulePath = (($newEnvPSModulePath).Split(";") | ? { $_ -ne $azureModulePath }) -join ";" + write-verbose "$azureModulePath removed. Restart the prompt for the changes to take effect." + } + else { + write-verbose "$azureModulePath is not present in $newEnvPSModulePath" + } + + $azPSModulePath = "C:\Modules\az_3.1.0" + $env:PSModulePath = $azPSModulePath + ";" + $newEnvPSModulePath } \ No newline at end of file diff --git a/Tasks/AzureFileCopyV4/task.json b/Tasks/AzureFileCopyV4/task.json index b04317864b1b..f5791654a504 100644 --- a/Tasks/AzureFileCopyV4/task.json +++ b/Tasks/AzureFileCopyV4/task.json @@ -13,7 +13,7 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 165, + "Minor": 166, "Patch": 0 }, "preview": true, diff --git a/Tasks/AzureFileCopyV4/task.loc.json b/Tasks/AzureFileCopyV4/task.loc.json index 211234676fc0..30fd8a0c937e 100644 --- a/Tasks/AzureFileCopyV4/task.loc.json +++ b/Tasks/AzureFileCopyV4/task.loc.json @@ -13,7 +13,7 @@ "author": "Microsoft Corporation", "version": { "Major": 4, - "Minor": 165, + "Minor": 166, "Patch": 0 }, "preview": true,