Skip to content

Commit 9a4861b

Browse files
[windows] switch to Powershell Gallery when preparing Azure modules (#8264)
1 parent 878fa3c commit 9a4861b

File tree

3 files changed

+11
-52
lines changed

3 files changed

+11
-52
lines changed

images/win/scripts/Installers/Install-AzureModules.ps1

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
################################################################################
22
## File: Install-AzureModules.ps1
33
## Desc: Install Azure PowerShell modules
4+
## Supply chain security: package manager
45
################################################################################
56

7+
#
8+
# prepares the environment for the Azure PowerShell modules
9+
# used by AzureFileCopy@4, AzureFileCopy@5, AzurePowerShell@4, AzurePowerShell@5 tasks
10+
#
11+
612
# The correct Modules need to be saved in C:\Modules
713
$installPSModulePath = "C:\\Modules"
814
if (-not (Test-Path -LiteralPath $installPSModulePath))
@@ -25,56 +31,15 @@ foreach ($module in $modules)
2531
{
2632
$modulePath = Join-Path -Path $installPSModulePath -ChildPath "${moduleName}_${version}"
2733
Write-Host " - $version [$modulePath]"
28-
try
29-
{
30-
Save-Module -Path $modulePath -Name $moduleName -RequiredVersion $version -Force -ErrorAction Stop
31-
}
32-
catch
33-
{
34-
Write-Host "Error: $_"
35-
exit 1
36-
}
37-
}
38-
39-
if($null -ne $module.url)
40-
{
41-
$assets = Invoke-RestMethod $module.url
34+
Save-Module -Path $modulePath -Name $moduleName -RequiredVersion $version -Force -ErrorAction Stop
4235
}
4336

4437
foreach ($version in $module.zip_versions)
4538
{
46-
# Install modules from GH Release
47-
if($null -ne $assets)
48-
{
49-
$asset = $assets | Where-Object version -eq $version `
50-
| Select-Object -ExpandProperty files `
51-
| Select-Object -First 1
52-
53-
Write-Host "Installing $($module.name) $version ..."
54-
if ($null -ne $asset) {
55-
Start-DownloadWithRetry -Url $asset.download_url -Name $asset.filename -DownloadPath $installPSModulePath
56-
} else {
57-
Write-Host "Asset was not found in versions manifest"
58-
exit 1
59-
}
60-
}
61-
# Install modules from vsts blob
62-
else
63-
{
64-
$modulePath = Join-Path -Path $installPSModulePath -ChildPath "${moduleName}_${version}"
65-
$filename = "${moduleName}_${version}.zip"
66-
$download_url = [System.String]::Concat($module.blob_url,$filename)
67-
Write-Host " - $version [$modulePath]"
68-
try
69-
{
70-
Start-DownloadWithRetry -Url $download_url -Name $filename -DownloadPath $installPSModulePath
71-
}
72-
catch
73-
{
74-
Write-Host "Error: $_"
75-
exit 1
76-
}
77-
}
39+
$modulePath = Join-Path -Path $installPSModulePath -ChildPath "${moduleName}_${version}"
40+
Save-Module -Path $modulePath -Name $moduleName -RequiredVersion $version -Force -ErrorAction Stop
41+
Compress-Archive -Path $modulePath -DestinationPath "${modulePath}.zip"
42+
Remove-Item $modulePath -Recurse -Force
7843
}
7944
# Append default tool version to machine path
8045
if ($null -ne $module.default)

images/win/toolsets/toolset-2019.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
"azureModules": [
9797
{
9898
"name": "azurerm",
99-
"blob_url": "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/",
10099
"versions": [
101100
"2.1.0",
102101
"6.13.1"
@@ -111,7 +110,6 @@
111110
},
112111
{
113112
"name": "azure",
114-
"blob_url": "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/",
115113
"versions": [
116114
"2.1.0",
117115
"5.3.0"
@@ -125,7 +123,6 @@
125123
},
126124
{
127125
"name": "az",
128-
"url" : "https://raw.githubusercontent.com/Azure/az-ps-module-versions/main/versions-manifest.json",
129126
"versions": [
130127
"9.3.0"
131128
],

images/win/toolsets/toolset-2022.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
"azureModules": [
9191
{
9292
"name": "azurerm",
93-
"blob_url": "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/",
9493
"versions": [
9594
"2.1.0",
9695
"6.13.1"
@@ -105,7 +104,6 @@
105104
},
106105
{
107106
"name": "azure",
108-
"blob_url": "https://vstsagenttools.blob.core.windows.net/tools/azurepowershellmodules/",
109107
"versions": [
110108
"2.1.0",
111109
"5.3.0"
@@ -119,7 +117,6 @@
119117
},
120118
{
121119
"name": "az",
122-
"url" : "https://raw.githubusercontent.com/Azure/az-ps-module-versions/main/versions-manifest.json",
123120
"versions": [
124121
"9.3.0"
125122
],

0 commit comments

Comments
 (0)