Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate tasks from deprecated AzureRM powershell functions to AZ powershell functions #19752

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Tasks/AzureCloudPowerShellDeploymentV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 0
"Patch": 1
},
"demands": [
"azureps"
Expand Down Expand Up @@ -284,4 +284,4 @@
"AllRoleInstancesAreReady": "All role instances (count: '{1}') for Azure Cloud Service: '{0}' are in 'ReadyRole' state.",
"AzureCloudServiceNotFound": "Azure Cloud Service: '{0}' not found."
}
}
}
2 changes: 1 addition & 1 deletion Tasks/AzureCloudPowerShellDeploymentV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 0
"Patch": 1
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCloudPowerShellDeploymentV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 0
"Patch": 1
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCloudPowerShellDeploymentV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 0
"Patch": 1
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 2
"Patch": 3
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 2
"Patch": 3
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 2
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 2
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 3,
"Minor": 238,
"Patch": 2
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 3,
"Minor": 238,
"Patch": 2
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 4,
"Minor": 238,
"Patch": 2
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 4,
"Minor": 238,
"Patch": 2
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV5/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 5,
"Minor": 238,
"Patch": 4
"Patch": 6
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV5/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 5,
"Minor": 238,
"Patch": 4
"Patch": 6
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV6/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 6,
"Minor": 238,
"Patch": 4
"Patch": 6
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV6/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 6,
"Minor": 238,
"Patch": 4
"Patch": 6
},
"demands": [
"azureps"
Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzurePowerShellV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 0
"Patch": 1
},
"demands": [
"azureps"
Expand Down Expand Up @@ -150,4 +150,4 @@
"InvalidAzurePsVersion": "The Azure PowerShell version '{0}' specified is not in the correct format. Please check the format. An example of correct format is 1.0.1",
"OverrideAzurePowerShellVersion": "The Azure PowerShell version '{0}' is not supported for Hosted Agent. Overriding it with version '{1}'. Consider changing the version selected."
}
}
}
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 238,
"Patch": 0
"Patch": 1
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 3,
"Minor": 238,
"Patch": 6
"Patch": 7
},
"releaseNotes": "Added support for Fail on standard error and ErrorActionPreference",
"demands": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 3,
"Minor": 238,
"Patch": 6
"Patch": 7
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"demands": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 238,
"Patch": 2
"Patch": 4
},
"releaseNotes": "Added support for Az Module and cross platform agents.",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 238,
"Patch": 2
"Patch": 4
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV5/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 5,
"Minor": 238,
"Patch": 6
"Patch": 8
},
"releaseNotes": "Added support for Az Module and cross platform agents.",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV5/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 5,
"Minor": 238,
"Patch": 6
"Patch": 8
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"groups": [
Expand Down
97 changes: 49 additions & 48 deletions Tasks/Common/VstsAzureHelpers_/InitializeAzModuleFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,40 @@ function Initialize-AzModule {
Write-Verbose "Importing Az Modules."

if ($featureFlags.retireAzureRM) {
$azAccountsModuleName = "Az.Accounts"
$azAccountsVersion = Import-SpecificAzModule -moduleName $azAccountsModuleName
Write-Verbose "'$azAccountsModuleName' is available with version $azAccountsVersion."
# Supress breaking changes messages
Set-Item -Path Env:\SuppressAzurePowerShellBreakingChangeWarnings -Value $true
$azureRMUninstalled = $false;

# If Az.Account already installed, remove RM modules
if (Get-Module -ListAvailable -Name Az.Accounts) {
Uninstall-AzureRMModules
$azureRMUninstalled = $true;
} else {
$azAccountsModuleName = "Az.Accounts"
$azAccountsVersion = Import-SpecificAzModule -moduleName $azAccountsModuleName
Write-Verbose "'$azAccountsModuleName' is available with version $azAccountsVersion."
}

# Update-AzConfig is a part of Az.Accounts
if (Get-Command Update-AzConfig -ErrorAction SilentlyContinue) {
Write-Verbose "Supressing breaking changes warnings of '$($azAccountsModuleName)' module."
Update-AzConfig -DisplayBreakingChangeWarning $false -AppliesTo $azAccountsModuleName
Write-Verbose "Supressing breaking changes warnings of Az module."
Update-AzConfig -DisplayBreakingChangeWarning $false -CheckForUpgrade $false -AppliesTo Az
} else {
Write-Verbose "Update-AzConfig cmdlet is not available."
}

Uninstall-AzureRMModules -UseAzUninstall
if ($azureRMUninstalled -eq $false) {
Uninstall-AzureRMModules
}

# Enable-AzureRmAlias for azureRm compability
if (Get-Command Enable-AzureRmAlias -ErrorAction SilentlyContinue) {
Write-Verbose "Enable-AzureRmAlias for backward compability"
Write-Host "##[command]Enable-AzureRmAlias -Scope Process"
DmitriiBobreshev marked this conversation as resolved.
Show resolved Hide resolved
Enable-AzureRmAlias -Scope Process
} else {
Write-Verbose "Enable-AzureRmAlias cmdlet is not available."
}

$azResourcesModuleName = "Az.Resources"
$azResourcesVersion = Import-SpecificAzModule -moduleName $azResourcesModuleName
Expand Down Expand Up @@ -84,28 +106,27 @@ function Import-SpecificAzModule {

Trace-VstsEnteringInvocation $MyInvocation
try {
# Write-Verbose "Attempting to find the latest available version of module '$moduleName'."
# $module = Get-Module -Name $moduleName -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1

# if ($module) {
# Write-Verbose "Module '$moduleName' version $($module.Version) was found."
# }
# else {
# Write-Verbose "Unable to find module '$moduleName' from the module path. Installing '$moduleName' module."
Write-Verbose "Attempting to find the latest available version of module '$moduleName'."
$module = Get-Module -Name $moduleName -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1

Write-Host "##[command]Install-Module -Name $moduleName -Force -AllowClobber -ErrorAction Stop"
Install-Module -Name $moduleName -Force -AllowClobber -ErrorAction Stop
# }
if ($module) {
Write-Verbose "Module '$moduleName' version $($module.Version) was found."
}
else {
Write-Verbose "Unable to find module '$moduleName' from the module path. Installing '$moduleName' module."

$module = Get-Module -Name $moduleName -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
Write-Host "##[command]Install-Module -Name $moduleName -Force -AllowClobber -ErrorAction Stop"
Install-Module -Name $moduleName -Force -AllowClobber -ErrorAction Stop
$module = Get-Module -Name $moduleName -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
}

if (-not $module) {
Write-Warning "Unable to install '$moduleName'."
throw (Get-VstsLocString -Key AZ_ModuleNotFound -ArgumentList $moduleName)
}

Write-Host "##[command]Import-Module -Name $($module.Path) -Global -PassThru -Force"
$module = (Import-Module -Name $moduleName -Global -PassThru -Force | Sort-Object Version -Descending | Select-Object -First 1)[0]
Write-Host "##[command]Import-Module -Name $($module.Path) -DisableNameChecking -Global -PassThru -Force"
$module = (Import-Module -Name $moduleName -DisableNameChecking -Global -PassThru -Force | Sort-Object Version -Descending | Select-Object -First 1)[0]
Write-Host("Imported module '$moduleName', version: $($module.Version)")

return $module.Version
Expand Down Expand Up @@ -166,48 +187,28 @@ function Import-AzAccountsModule {
}

function Uninstall-AzureRMModules {
[CmdletBinding()]
param([switch] $UseAzUninstall)
[CmdletBinding()]Param()

Trace-VstsEnteringInvocation $MyInvocation
try {
Write-Verbose "Uninstalling AzureRM modules."

if ($UseAzUninstall -and (Get-Module -ListAvailable -Name Az.Accounts)) {
if (Get-Module -ListAvailable -Name Az.Accounts) {
Write-Host "##[command]Uninstall-AzureRm"
Uninstall-AzureRm
}
else {

Write-Verbose "Making sure all AzureRM modules are gone after the uninstall."

$azureRmModules = Get-Module -ListAvailable -Name AzureRM.* | Select-Object Name,Version
if ($azureRmModules -and $azureRmModules.Count -gt 0) {
if ($azureRmModules) {
Foreach ($azureRmModule in $azureRmModules) {
$azureRmModuleName = $azureRmModule.Name
Write-Verbose "Uninstalling module: $azureRmModuleName"
try {
Write-Host "##[command]Uninstall-Module -Name $azureRmModuleName -AllVersions -Force"
Uninstall-Module -Name $azureRmModuleName -AllVersions -Force
}
catch {
Write-Verbose "Failed to uninstall module: $azureRmModuleName"
}
Write-Verbose "'$($azureRmModule)' AzureRM module found."
}
}
else {
Write-Host "No AzureRM modules found to uninstall."
Write-Verbose "No AzureRM modules found."
}
}

Write-Verbose "Making sure all AzureRM modules are gone after the uninstall."

$azureRmModules = Get-Module -ListAvailable -Name AzureRM.* | Select-Object Name,Version
if ($azureRmModules) {
Foreach ($azureRmModule in $azureRmModules) {
Write-Verbose "'$($azureRmModule)' AzureRM module found."
}
}
else {
Write-Verbose "No AzureRM modules found."
}
}
finally {
Trace-VstsLeavingInvocation $MyInvocation
Expand Down
4 changes: 2 additions & 2 deletions Tasks/SqlAzureDacpacDeploymentV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 238,
"Patch": 0
"Patch": 1
},
"demands": [
"sqlpackage"
Expand Down Expand Up @@ -368,4 +368,4 @@
"SAD_InvokeSQLCmdNotSupportingConnectionString": "Imported Invoke-Sqlcmd doesn't support connectionString. Install SQLServer PS module.",
"SAD_NoServerSpecified": "No server specified. Please specify a source or a target server."
}
}
}
Loading