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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 9 additions & 4 deletions
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

Lines changed: 36 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 38 additions & 0 deletions
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
}

0 commit comments

Comments
 (0)