Skip to content

Commit b93fa97

Browse files
AzureRM deprecation (#20079)
* AzureRM deprecation - removed modules import from core function * fix for AzureFileCopy * fix for AzureFileCopy * fix for AzureFileCopy * Fix AzureFileCopy connection * Fix AzureFileCopy connection * Fix tests for AzurePowerShellV2/V3 * Import latest added az powershell --------- Co-authored-by: Ivan Duplenskikh <[email protected]>
1 parent d8e6a2e commit b93fa97

File tree

82 files changed

+547
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+547
-238
lines changed

Tasks/AzureCloudPowerShellDeploymentV1/task.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"author": "Microsoft Corporation",
1717
"version": {
1818
"Major": 1,
19-
"Minor": 241,
20-
"Patch": 1
19+
"Minor": 242,
20+
"Patch": 0
2121
},
2222
"demands": [
2323
"azureps"

Tasks/AzureCloudPowerShellDeploymentV1/task.loc.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"author": "Microsoft Corporation",
1717
"version": {
1818
"Major": 1,
19-
"Minor": 241,
20-
"Patch": 1
19+
"Minor": 242,
20+
"Patch": 0
2121
},
2222
"demands": [
2323
"azureps"

Tasks/AzureCloudPowerShellDeploymentV2/task.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"author": "Microsoft Corporation",
1717
"version": {
1818
"Major": 2,
19-
"Minor": 241,
20-
"Patch": 1
19+
"Minor": 242,
20+
"Patch": 0
2121
},
2222
"demands": [
2323
"azureps"

Tasks/AzureCloudPowerShellDeploymentV2/task.loc.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"author": "Microsoft Corporation",
1717
"version": {
1818
"Major": 2,
19-
"Minor": 241,
20-
"Patch": 1
19+
"Minor": 242,
20+
"Patch": 0
2121
},
2222
"demands": [
2323
"azureps"

Tasks/AzureFileCopyV1/AzureFileCopy.ps1

+9-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ $containerName = $containerName.Trim().ToLower()
5454
$azCopyExeLocation = 'AzCopy\AzCopy.exe'
5555
$azCopyLocation = [System.IO.Path]::GetDirectoryName($azCopyExeLocation)
5656

57-
# Initialize Azure.
58-
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
59-
Initialize-Azure
60-
6157
# Import the loc strings.
6258
Import-VstsLocStrings -LiteralPath $PSScriptRoot/Task.json
6359

@@ -69,6 +65,15 @@ Import-Module "$PSScriptRoot\DeploymentUtilities\Microsoft.TeamFoundation.Distri
6965
. "$PSScriptRoot\AzureFileCopyJob.ps1"
7066
. "$PSScriptRoot\Utility.ps1"
7167

68+
if ($featureFlags.retireAzureRM)
69+
{
70+
Modify-PSModulePathForHostedAgent
71+
}
72+
73+
# Initialize Azure.
74+
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
75+
Initialize-Azure
76+
7277
# Enabling detailed logging only when system.debug is true
7378
$enableDetailedLoggingString = $env:system_debug
7479
if ($enableDetailedLoggingString -ne "true")

Tasks/AzureFileCopyV1/Utility.ps1

+36
Original file line numberDiff line numberDiff line change
@@ -1454,4 +1454,40 @@ function Check-ContainerNameAndArgs
14541454
{
14551455
Write-Warning (Get-vstsLocString -Key "AFC_RootContainerAndDirectory")
14561456
}
1457+
}
1458+
1459+
function Modify-PSModulePathForHostedAgent {
1460+
$newEnvPSModulePath = $env:PSModulePath
1461+
1462+
if (Test-Path "C:\Modules\az_*") {
1463+
$azPSModulePath = (Get-ChildItem "C:\Modules\az_*" -Directory `
1464+
| Sort-Object { [version]$_.Name.Split('_')[-1] } `
1465+
| Select-Object -Last 1).FullName
1466+
1467+
Write-Verbose "Found Az module path $azPSModulePath, will be used"
1468+
$env:PSModulePath = ($azPSModulePath + ";" + $newEnvPSModulePath).Trim(";")
1469+
}
1470+
1471+
Import-AzModule -moduleName "Az.Resources"
1472+
Import-AzModule -moduleName "Az.Storage"
1473+
Import-AzModule -moduleName "Az.Compute"
1474+
Import-AzModule -moduleName "Az.Network"
1475+
}
1476+
1477+
function Import-AzModule
1478+
{
1479+
param([string]$moduleName)
1480+
1481+
if (!(Get-Module $moduleName))
1482+
{
1483+
$module = Get-Module -Name $moduleName -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
1484+
if (!$module) {
1485+
Write-Verbose "No module found with name: $moduleName"
1486+
}
1487+
else {
1488+
# Import the module.
1489+
Write-Host "##[command]Import-Module -Name $($module.Path) -Global"
1490+
$module = Import-Module -Name $module.Path -Global -PassThru -Force
1491+
}
1492+
}
14571493
}

Tasks/AzureFileCopyV1/task.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 1,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 1
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV1/task.loc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 1,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 1
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV2/AzureFileCopy.ps1

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ Import-Module $PSScriptRoot\ps_modules\RemoteDeployer
7171
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
7272

7373
. "$PSScriptRoot\Utility.ps1"
74+
75+
if ($featureFlags.retireAzureRM)
76+
{
77+
Modify-PSModulePathForHostedAgent
78+
}
79+
7480
$endpoint = Get-Endpoint -connectedServiceName $connectedServiceName
7581
Update-PSModulePathForHostedAgentWithLatestModule -Endpoint $endpoint
7682
Initialize-Azure

Tasks/AzureFileCopyV2/Utility.ps1

+38
Original file line numberDiff line numberDiff line change
@@ -1462,4 +1462,42 @@ function Get-InvokeRemoteScriptParameters
14621462
protocol = $protocol;
14631463
sessionOption = $sessionOption
14641464
}
1465+
}
1466+
1467+
1468+
function Modify-PSModulePathForHostedAgent {
1469+
$newEnvPSModulePath = $env:PSModulePath
1470+
1471+
if (Test-Path "C:\Modules\az_*") {
1472+
$azPSModulePath = (Get-ChildItem "C:\Modules\az_*" -Directory `
1473+
| Sort-Object { [version]$_.Name.Split('_')[-1] } `
1474+
| Select-Object -Last 1).FullName
1475+
1476+
Write-Verbose "Found Az module path $azPSModulePath, will be used"
1477+
$env:PSModulePath = ($azPSModulePath + ";" + $newEnvPSModulePath).Trim(";")
1478+
}
1479+
1480+
1481+
Import-AzModule -moduleName "Az.Resources"
1482+
Import-AzModule -moduleName "Az.Storage"
1483+
Import-AzModule -moduleName "Az.Compute"
1484+
Import-AzModule -moduleName "Az.Network"
1485+
}
1486+
1487+
function Import-AzModule
1488+
{
1489+
param([string]$moduleName)
1490+
1491+
if (!(Get-Module $moduleName))
1492+
{
1493+
$module = Get-Module -Name $moduleName -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
1494+
if (!$module) {
1495+
Write-Verbose "No module found with name: $moduleName"
1496+
}
1497+
else {
1498+
# Import the module.
1499+
Write-Host "##[command]Import-Module -Name $($module.Path) -Global"
1500+
$module = Import-Module -Name $module.Path -Global -PassThru -Force
1501+
}
1502+
}
14651503
}

Tasks/AzureFileCopyV2/task.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 2,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV2/task.loc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 2,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV3/AzureFileCopy.ps1

+8-7
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,19 @@ Import-Module $PSScriptRoot\ps_modules\RemoteDeployer
6767
# Initialize Azure.
6868
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
6969

70+
# Import the loc strings.
71+
Import-VstsLocStrings -LiteralPath $PSScriptRoot/Task.json
72+
73+
# Load all dependent files for execution
74+
. "$PSScriptRoot\AzureFileCopyRemoteJob.ps1"
75+
. "$PSScriptRoot\Utility.ps1"
76+
7077
$endpoint = Get-VstsEndpoint -Name $connectedServiceName -Require
7178
$vstsEndpoint = Get-VstsEndpoint -Name SystemVssConnection -Require
7279
$vstsAccessToken = $vstsEndpoint.auth.parameters.AccessToken
7380

7481
if ($featureFlags.retireAzureRM) {
82+
CleanUp-PSModulePathForHostedAgent
7583
Write-Verbose "Initializing Az Module."
7684
$encryptedToken = ConvertTo-SecureString $vstsAccessToken -AsPlainText -Force
7785
Initialize-AzModule -Endpoint $endpoint -connectedServiceNameARM $connectedServiceName -encryptedToken $encryptedToken
@@ -87,13 +95,6 @@ if ($featureFlags.retireAzureRM) {
8795
}
8896
}
8997

90-
# Import the loc strings.
91-
Import-VstsLocStrings -LiteralPath $PSScriptRoot/Task.json
92-
93-
# Load all dependent files for execution
94-
. "$PSScriptRoot\AzureFileCopyRemoteJob.ps1"
95-
. "$PSScriptRoot\Utility.ps1"
96-
9798
# Enabling detailed logging only when system.debug is true
9899
$enableDetailedLogging = ($env:system_debug -eq "true")
99100

Tasks/AzureFileCopyV3/Utility.ps1

+33
Original file line numberDiff line numberDiff line change
@@ -1293,4 +1293,37 @@ function Get-InvokeRemoteScriptParameters
12931293
protocol = $protocol;
12941294
sessionOption = $sessionOption
12951295
}
1296+
}
1297+
1298+
function CleanUp-PSModulePathForHostedAgent {
1299+
1300+
# Define the module paths to clean up
1301+
$modulePaths = @(
1302+
"C:\Modules\azurerm_2.1.0",
1303+
"C:\\Modules\azurerm_2.1.0",
1304+
"C:\Modules\azure_2.1.0",
1305+
"C:\\Modules\azure_2.1.0"
1306+
)
1307+
1308+
# Clean up PSModulePath for hosted agent
1309+
$newEnvPSModulePath = $env:PSModulePath
1310+
1311+
foreach ($modulePath in $modulePaths) {
1312+
if ($newEnvPSModulePath.split(";") -contains $modulePath) {
1313+
$newEnvPSModulePath = (($newEnvPSModulePath).Split(";") | ? { $_ -ne $modulePath }) -join ";"
1314+
Write-Verbose "$modulePath removed. Restart the prompt for the changes to take effect."
1315+
}
1316+
else {
1317+
Write-Verbose "$modulePath is not present in $newEnvPSModulePath"
1318+
}
1319+
}
1320+
1321+
if (Test-Path "C:\Modules\az_*") {
1322+
$azPSModulePath = (Get-ChildItem "C:\Modules\az_*" -Directory `
1323+
| Sort-Object { [version]$_.Name.Split('_')[-1] } `
1324+
| Select-Object -Last 1).FullName
1325+
1326+
Write-Verbose "Found Az module path $azPSModulePath, will be used"
1327+
$env:PSModulePath = ($azPSModulePath + ";" + $newEnvPSModulePath).Trim(";")
1328+
}
12961329
}

Tasks/AzureFileCopyV3/task.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 3,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV3/task.loc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 3,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV4/task.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 4,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV4/task.loc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 4,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV5/task.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 5,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV5/task.loc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 5,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV6/task.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 6,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

Tasks/AzureFileCopyV6/task.loc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 6,
1616
"Minor": 242,
17-
"Patch": 0
17+
"Patch": 2
1818
},
1919
"demands": [
2020
"azureps"

0 commit comments

Comments
 (0)