[windows] switch to Powershell Gallery when preparing Azure modules (#8264)

This commit is contained in:
ilia-shipitsin
2023-09-12 10:04:14 +02:00
committed by GitHub
parent 878fa3c8d6
commit 9a4861b4ee
3 changed files with 11 additions and 52 deletions

View File

@@ -1,8 +1,14 @@
################################################################################
## File: Install-AzureModules.ps1
## Desc: Install Azure PowerShell modules
## Supply chain security: package manager
################################################################################
#
# prepares the environment for the Azure PowerShell modules
# used by AzureFileCopy@4, AzureFileCopy@5, AzurePowerShell@4, AzurePowerShell@5 tasks
#
# The correct Modules need to be saved in C:\Modules
$installPSModulePath = "C:\\Modules"
if (-not (Test-Path -LiteralPath $installPSModulePath))
@@ -25,56 +31,15 @@ foreach ($module in $modules)
{
$modulePath = Join-Path -Path $installPSModulePath -ChildPath "${moduleName}_${version}"
Write-Host " - $version [$modulePath]"
try
{
Save-Module -Path $modulePath -Name $moduleName -RequiredVersion $version -Force -ErrorAction Stop
}
catch
{
Write-Host "Error: $_"
exit 1
}
}
if($null -ne $module.url)
{
$assets = Invoke-RestMethod $module.url
Save-Module -Path $modulePath -Name $moduleName -RequiredVersion $version -Force -ErrorAction Stop
}
foreach ($version in $module.zip_versions)
{
# Install modules from GH Release
if($null -ne $assets)
{
$asset = $assets | Where-Object version -eq $version `
| Select-Object -ExpandProperty files `
| Select-Object -First 1
Write-Host "Installing $($module.name) $version ..."
if ($null -ne $asset) {
Start-DownloadWithRetry -Url $asset.download_url -Name $asset.filename -DownloadPath $installPSModulePath
} else {
Write-Host "Asset was not found in versions manifest"
exit 1
}
}
# Install modules from vsts blob
else
{
$modulePath = Join-Path -Path $installPSModulePath -ChildPath "${moduleName}_${version}"
$filename = "${moduleName}_${version}.zip"
$download_url = [System.String]::Concat($module.blob_url,$filename)
Write-Host " - $version [$modulePath]"
try
{
Start-DownloadWithRetry -Url $download_url -Name $filename -DownloadPath $installPSModulePath
}
catch
{
Write-Host "Error: $_"
exit 1
}
}
$modulePath = Join-Path -Path $installPSModulePath -ChildPath "${moduleName}_${version}"
Save-Module -Path $modulePath -Name $moduleName -RequiredVersion $version -Force -ErrorAction Stop
Compress-Archive -Path $modulePath -DestinationPath "${modulePath}.zip"
Remove-Item $modulePath -Recurse -Force
}
# Append default tool version to machine path
if ($null -ne $module.default)

View File

@@ -96,7 +96,6 @@
"azureModules": [
{
"name": "azurerm",
"blob_url": "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/",
"versions": [
"2.1.0",
"6.13.1"
@@ -111,7 +110,6 @@
},
{
"name": "azure",
"blob_url": "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/",
"versions": [
"2.1.0",
"5.3.0"
@@ -125,7 +123,6 @@
},
{
"name": "az",
"url" : "https://raw.githubusercontent.com/Azure/az-ps-module-versions/main/versions-manifest.json",
"versions": [
"9.3.0"
],

View File

@@ -90,7 +90,6 @@
"azureModules": [
{
"name": "azurerm",
"blob_url": "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/",
"versions": [
"2.1.0",
"6.13.1"
@@ -105,7 +104,6 @@
},
{
"name": "azure",
"blob_url": "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/",
"versions": [
"2.1.0",
"5.3.0"
@@ -119,7 +117,6 @@
},
{
"name": "az",
"url" : "https://raw.githubusercontent.com/Azure/az-ps-module-versions/main/versions-manifest.json",
"versions": [
"9.3.0"
],