diff --git a/images/windows/scripts/build/Install-MongoDB.ps1 b/images/windows/scripts/build/Install-MongoDB.ps1 index a45dbc5623..d1bd27897c 100644 --- a/images/windows/scripts/build/Install-MongoDB.ps1 +++ b/images/windows/scripts/build/Install-MongoDB.ps1 @@ -7,20 +7,21 @@ $toolsetContent = Get-ToolsetContent $toolsetVersion = $toolsetContent.mongodb.version -$getMongoReleases = Invoke-WebRequest -Uri "mongodb.com/docs/v$toolsetVersion/release-notes/$toolsetVersion/" -UseBasicParsing -$targetReleases = $getMongoReleases.Links.href | Where-Object { $_ -like "#$toolsetVersion*---*" } - -$minorVersions = @() -foreach ($release in $targetReleases) { - if ($release -notlike "*upcoming*") { - $pattern = '\d+\.\d+\.\d+' - $version = $release | Select-String -Pattern $pattern -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } - $minorVersions += $version - } +# Resolve the latest patch release from the downloads feed rather than the release notes +# page. The feed lists the newest release of each supported branch and is not subject to the +# markup and URL changes that repeatedly broke scraping the docs. +$mongoReleasesUrl = "https://downloads.mongodb.org/current.json" +$mongoReleases = Invoke-RestMethod -Uri $mongoReleasesUrl + +$latestVersion = $mongoReleases.versions.version | + Where-Object { $_ -like "$toolsetVersion.*" } | + Sort-Object { [version]$_ } -Descending | + Select-Object -First 1 + +if (-not $latestVersion) { + throw "Unable to resolve latest MongoDB $toolsetVersion release from $mongoReleasesUrl" } -$latestVersion = $minorVersions[0] - Install-Binary ` -Url "https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-$latestVersion-signed.msi" ` -ExtraInstallArgs @('TARGETDIR=C:\PROGRA~1\MongoDB ADDLOCAL=ALL') `