Skip to content

Commit

Permalink
Update dotnet download Installer Url and Added a fallback check (#20752)
Browse files Browse the repository at this point in the history
* Update dotnet download Url and Added a fallback check

* code review changes for changing dotnet installer link

* code review changes for changing dotnet installer link

---------

Co-authored-by: Sanju Yadav <[email protected]>
  • Loading branch information
sanjuyadav24 and Sanju Yadav authored Dec 24, 2024
1 parent cc4095f commit bad5399
Show file tree
Hide file tree
Showing 25 changed files with 210 additions and 74 deletions.
28 changes: 20 additions & 8 deletions Tasks/DotNetCoreInstallerV0/externals/install-dotnet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
.PARAMETER Verbose
Displays diagnostics information.
.PARAMETER AzureFeed
Default: https://dotnetcli.azureedge.net/dotnet
Default: https://builds.dotnet.microsoft.com/dotnet
This parameter typically is not changed by the user.
It allows to change URL for the Azure feed used by this installer.
.PARAMETER UncachedFeed
Expand All @@ -68,7 +68,8 @@ param(
[switch]$SharedRuntime,
[switch]$DryRun,
[switch]$NoPath,
[string]$AzureFeed="https://dotnetcli.azureedge.net/dotnet",
[string]$AzureFeed="https://builds.dotnet.microsoft.com/dotnet",
[string]$FallbackAzureFeed="https://dotnetcli.azureedge.net/dotnet",
[string]$UncachedFeed="https://dotnetcli.blob.core.windows.net/dotnet",
[string]$ProxyAddress,
[switch]$ProxyUseDefaultCredentials
Expand Down Expand Up @@ -446,12 +447,14 @@ function Prepend-Sdk-InstallRoot-To-Path([string]$InstallRoot, [string]$BinFolde
$CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture
$SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -Channel $Channel -Version $Version
$DownloadLink = Get-Download-Link -AzureFeed $AzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
$FallbackDownloadLink = Get-Download-Link -AzureFeed $FallbackAzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
$LegacyDownloadLink = Get-LegacyDownload-Link -AzureFeed $AzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture

if ($DryRun) {
Say "Payload URLs:"
Say "Primary - $DownloadLink"
Say "Legacy - $LegacyDownloadLink"
Say "Fallback - $FallbackDownloadLink"
Say "Repeatable invocation: .\$($MyInvocation.MyCommand) -Version $SpecificVersion -Channel $Channel -Architecture $CLIArchitecture -InstallDir $InstallDir"
exit 0
}
Expand Down Expand Up @@ -484,12 +487,21 @@ try {
DownloadFile -Uri $DownloadLink -OutPath $ZipPath
}
catch {
Say "Cannot download: $DownloadLink"
$DownloadLink = $LegacyDownloadLink
$ZipPath = [System.IO.Path]::GetTempFileName()
Say-Verbose "Legacy zip path: $ZipPath"
Say "Downloading legacy link: $DownloadLink"
DownloadFile -Uri $DownloadLink -OutPath $ZipPath
try {
Say "Cannot download: $DownloadLink"
$DownloadLink = $FallbackDownloadLink
$ZipPath = [System.IO.Path]::GetTempFileName()
Say-Verbose "Fallabck zip path: $ZipPath"
Say "Downloading fallback link: $FallbackDownloadLink"
DownloadFile -Uri $FallbackDownloadLink -OutPath $ZipPath
} catch {
Say "Cannot download: $FallbackDownloadLink"
$DownloadLink = $LegacyDownloadLink
$ZipPath = [System.IO.Path]::GetTempFileName()
Say-Verbose "Legacy zip path: $ZipPath"
Say "Downloading legacy link: $DownloadLink"
DownloadFile -Uri $DownloadLink -OutPath $ZipPath
}
}

Say "Extracting zip from $DownloadLink"
Expand Down
21 changes: 19 additions & 2 deletions Tasks/DotNetCoreInstallerV0/externals/install-dotnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ calculate_vars() {
download_link=$(construct_download_link $azure_feed $channel $normalized_architecture $specific_version)
say_verbose "download_link=$download_link"

fallback_download_link=$(construct_download_link $fallback_azure_feed $channel $normalized_architecture $specific_version)
say_verbose "fallback_download_link=$fallback_download_link"

legacy_download_link=$(construct_legacy_download_link $azure_feed $channel $normalized_architecture $specific_version) || valid_legacy_download_link=false

if [ "$valid_legacy_download_link" = true ]; then
Expand All @@ -643,6 +646,7 @@ calculate_vars() {
install_dotnet() {
eval $invocation
local download_failed=false
local fallback_download_failed=false

if is_dotnet_package_installed $install_root "sdk" $specific_version; then
say ".NET SDK version $specific_version is already installed."
Expand All @@ -656,8 +660,20 @@ install_dotnet() {
say "Downloading link: $download_link"
download "$download_link" $zip_path || download_failed=true

say_verbose "download_failed: $download_failed"

if [ "$download_failed" = true ]; then
say "Cannot download: $download_link"
download_link=$fallback_download_link
zip_path=$(mktemp $temporary_file_template)
say_verbose "Fallback zip path: $zip_path"
say "Downloading fallback link: $download_link"
download "$download_link" $zip_path || fallback_download_failed=true
fi

say_verbose "valid_legacy_download_link: $valid_legacy_download_link"
# if the download fails, download the legacy_download_link
if [ "$download_failed" = true ] && [ "$valid_legacy_download_link" = true ]; then
if [ "$fallback_download_failed" = true ] && [ "$valid_legacy_download_link" = true ]; then
say "Cannot download: $download_link"
download_link=$legacy_download_link
zip_path=$(mktemp $temporary_file_template)
Expand All @@ -682,7 +698,8 @@ install_dir="<auto>"
architecture="<auto>"
dry_run=false
no_path=false
azure_feed="https://dotnetcli.azureedge.net/dotnet"
fallback_azure_feed="https://dotnetcli.azureedge.net/dotnet"
azure_feed="https://builds.dotnet.microsoft.com/dotnet"
uncached_feed="https://dotnetcli.blob.core.windows.net/dotnet"
verbose=false
shared_runtime=false
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DotNetCoreInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 247,
"Minor": 250,
"Patch": 0
},
"satisfies": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DotNetCoreInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 247,
"Minor": 250,
"Patch": 0
},
"satisfies": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/UseDotNetV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 248,
"Minor": 250,
"Patch": 0
},
"satisfies": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/UseDotNetV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 248,
"Minor": 250,
"Patch": 0
},
"satisfies": [
Expand Down
19 changes: 15 additions & 4 deletions Tasks/UseDotNetV2/versioninstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ export class VersionInstaller {
var downloadPath = await toolLib.downloadToolWithRetries(downloadUrl)
}
catch (ex) {
tl.warning(tl.loc("CouldNotDownload", downloadUrl, ex));
let fallBackUrl = `https://dotnetcli.azureedge.net/dotnet/${this.packageType === "runtime" ? "Runtime" : "Sdk"}/${version}/${downloadUrl.substring(downloadUrl.lastIndexOf('/') + 1)}`;
console.log("Using fallback url for download: " + fallBackUrl);
var downloadPath = await toolLib.downloadToolWithRetries(fallBackUrl)
let feedFallbackUrl = "https://builds.dotnet.microsoft.com/dotnet";
try {
tl.warning(tl.loc("CouldNotDownload", downloadUrl, ex));
var downloadPath = await this.downloadFromFallbackUrl(feedFallbackUrl, this.packageType, version, downloadUrl);
} catch(ex) {
tl.warning(tl.loc("CouldNotDownload", feedFallbackUrl, ex));
var downloadPath = await this.downloadFromFallbackUrl("https://dotnetcli.azureedge.net/dotnet", this.packageType, version, downloadUrl);
}
}

// Extract
Expand Down Expand Up @@ -176,6 +180,13 @@ export class VersionInstaller {
throw tl.loc("FileNameNotCorrectCompleteFileName", name);
}

private async downloadFromFallbackUrl(fallBackUrl: string, packageType: string, version: string, downloadUrl: string) : Promise<string> {
let url = `${fallBackUrl}/${packageType === "runtime" ? "Runtime" : "Sdk"}/${version}/${downloadUrl.substring(downloadUrl.lastIndexOf('/') + 1)}`;
console.log("Using fallback url for download: " + url);
var downloadPath = await toolLib.downloadToolWithRetries(url)
return downloadPath;
}

private packageType: string;
private installationPath: string;
}
4 changes: 2 additions & 2 deletions _generated/DotNetCoreInstallerV0.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|0.247.0
Node20_229_3|0.247.1
Default|0.250.0
Node20_229_3|0.250.1
28 changes: 20 additions & 8 deletions _generated/DotNetCoreInstallerV0/externals/install-dotnet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
.PARAMETER Verbose
Displays diagnostics information.
.PARAMETER AzureFeed
Default: https://dotnetcli.azureedge.net/dotnet
Default: https://builds.dotnet.microsoft.com/dotnet
This parameter typically is not changed by the user.
It allows to change URL for the Azure feed used by this installer.
.PARAMETER UncachedFeed
Expand All @@ -68,7 +68,8 @@ param(
[switch]$SharedRuntime,
[switch]$DryRun,
[switch]$NoPath,
[string]$AzureFeed="https://dotnetcli.azureedge.net/dotnet",
[string]$AzureFeed="https://builds.dotnet.microsoft.com/dotnet",
[string]$FallbackAzureFeed="https://dotnetcli.azureedge.net/dotnet",
[string]$UncachedFeed="https://dotnetcli.blob.core.windows.net/dotnet",
[string]$ProxyAddress,
[switch]$ProxyUseDefaultCredentials
Expand Down Expand Up @@ -446,12 +447,14 @@ function Prepend-Sdk-InstallRoot-To-Path([string]$InstallRoot, [string]$BinFolde
$CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture
$SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -Channel $Channel -Version $Version
$DownloadLink = Get-Download-Link -AzureFeed $AzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
$FallbackDownloadLink = Get-Download-Link -AzureFeed $FallbackAzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
$LegacyDownloadLink = Get-LegacyDownload-Link -AzureFeed $AzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture

if ($DryRun) {
Say "Payload URLs:"
Say "Primary - $DownloadLink"
Say "Legacy - $LegacyDownloadLink"
Say "Fallback - $FallbackDownloadLink"
Say "Repeatable invocation: .\$($MyInvocation.MyCommand) -Version $SpecificVersion -Channel $Channel -Architecture $CLIArchitecture -InstallDir $InstallDir"
exit 0
}
Expand Down Expand Up @@ -484,12 +487,21 @@ try {
DownloadFile -Uri $DownloadLink -OutPath $ZipPath
}
catch {
Say "Cannot download: $DownloadLink"
$DownloadLink = $LegacyDownloadLink
$ZipPath = [System.IO.Path]::GetTempFileName()
Say-Verbose "Legacy zip path: $ZipPath"
Say "Downloading legacy link: $DownloadLink"
DownloadFile -Uri $DownloadLink -OutPath $ZipPath
try {
Say "Cannot download: $DownloadLink"
$DownloadLink = $FallbackDownloadLink
$ZipPath = [System.IO.Path]::GetTempFileName()
Say-Verbose "Fallabck zip path: $ZipPath"
Say "Downloading fallback link: $FallbackDownloadLink"
DownloadFile -Uri $FallbackDownloadLink -OutPath $ZipPath
} catch {
Say "Cannot download: $FallbackDownloadLink"
$DownloadLink = $LegacyDownloadLink
$ZipPath = [System.IO.Path]::GetTempFileName()
Say-Verbose "Legacy zip path: $ZipPath"
Say "Downloading legacy link: $DownloadLink"
DownloadFile -Uri $DownloadLink -OutPath $ZipPath
}
}

Say "Extracting zip from $DownloadLink"
Expand Down
21 changes: 19 additions & 2 deletions _generated/DotNetCoreInstallerV0/externals/install-dotnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ calculate_vars() {
download_link=$(construct_download_link $azure_feed $channel $normalized_architecture $specific_version)
say_verbose "download_link=$download_link"

fallback_download_link=$(construct_download_link $fallback_azure_feed $channel $normalized_architecture $specific_version)
say_verbose "fallback_download_link=$fallback_download_link"

legacy_download_link=$(construct_legacy_download_link $azure_feed $channel $normalized_architecture $specific_version) || valid_legacy_download_link=false

if [ "$valid_legacy_download_link" = true ]; then
Expand All @@ -643,6 +646,7 @@ calculate_vars() {
install_dotnet() {
eval $invocation
local download_failed=false
local fallback_download_failed=false

if is_dotnet_package_installed $install_root "sdk" $specific_version; then
say ".NET SDK version $specific_version is already installed."
Expand All @@ -656,8 +660,20 @@ install_dotnet() {
say "Downloading link: $download_link"
download "$download_link" $zip_path || download_failed=true

say_verbose "download_failed: $download_failed"

if [ "$download_failed" = true ]; then
say "Cannot download: $download_link"
download_link=$fallback_download_link
zip_path=$(mktemp $temporary_file_template)
say_verbose "Fallback zip path: $zip_path"
say "Downloading fallback link: $download_link"
download "$download_link" $zip_path || fallback_download_failed=true
fi

say_verbose "valid_legacy_download_link: $valid_legacy_download_link"
# if the download fails, download the legacy_download_link
if [ "$download_failed" = true ] && [ "$valid_legacy_download_link" = true ]; then
if [ "$fallback_download_failed" = true ] && [ "$valid_legacy_download_link" = true ]; then
say "Cannot download: $download_link"
download_link=$legacy_download_link
zip_path=$(mktemp $temporary_file_template)
Expand All @@ -682,7 +698,8 @@ install_dir="<auto>"
architecture="<auto>"
dry_run=false
no_path=false
azure_feed="https://dotnetcli.azureedge.net/dotnet"
fallback_azure_feed="https://dotnetcli.azureedge.net/dotnet"
azure_feed="https://builds.dotnet.microsoft.com/dotnet"
uncached_feed="https://dotnetcli.blob.core.windows.net/dotnet"
verbose=false
shared_runtime=false
Expand Down
7 changes: 4 additions & 3 deletions _generated/DotNetCoreInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 247,
"Minor": 250,
"Patch": 0
},
"satisfies": [
Expand Down Expand Up @@ -80,7 +80,8 @@
"UpdateToNewerVersion": "Kindly upgrade to new major version of this task 'Use .NET Core (2.*)' for installing newer versions of .NET Core. '0.*' task version might not be able to download newer .NET core versions. To know more about 'Use Dot Net (2.*)', refer https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/dotnet-core-tool-installer?view=azure-devops."
},
"_buildConfigMapping": {
"Default": "0.247.0",
"Node20_229_3": "0.247.1"
"Default": "0.250.0",
"LocalPackages": "0.249.4",
"Node20_229_3": "0.250.1"
}
}
7 changes: 4 additions & 3 deletions _generated/DotNetCoreInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 247,
"Minor": 250,
"Patch": 0
},
"satisfies": [
Expand Down Expand Up @@ -80,7 +80,8 @@
"UpdateToNewerVersion": "ms-resource:loc.messages.UpdateToNewerVersion"
},
"_buildConfigMapping": {
"Default": "0.247.0",
"Node20_229_3": "0.247.1"
"Default": "0.250.0",
"LocalPackages": "0.249.4",
"Node20_229_3": "0.250.1"
}
}
4 changes: 4 additions & 0 deletions _generated/DotNetCoreInstallerV0_Node20/.npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
scripts-prepend-node-path=true

registry=https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/

always-auth=true
Loading

0 comments on commit bad5399

Please sign in to comment.