Skip to content

Commit 42a2b00

Browse files
committed
Add catch to fallback to shipped pester if can't download nuget
1 parent ab44278 commit 42a2b00

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ Releases
5252
- 8.8.x - Add ScriptBlock parameter to allow running a script before running the tests. [Fixes #377](https://github.com/rfennell/vNextBuild/issues/377)
5353
- 8.11.x - Fixing Find-Module issues raised in [#412](https://github.com/rfennell/AzurePipelines/issues/412) and [415](https://github.com/rfennell/AzurePipelines/issues/415) by adding a check for AllowPrerelease switch on the cmdlet. If it's not available we'll fall back to the version of Pester that is shipped with the extension and write a warning that a newer version can't be used without a newer version of PowerShellGet being available.
5454
- 8.12.x - Updating built in version of Pester to 4.6.0. Remove check for AllowPrerelease as it's not needed. Fixes [#421](https://github.com/rfennell/AzurePipelines/issues/421)
55+
- 8.13.x - Update to better support offline build machines with no nuget installed. Falls back to shipped version of Pester. Fixes [#447](https://github.com/rfennell/AzurePipelines/issues/447)

task/Pester.ps1

+7-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ if ((Get-Module -Name PowerShellGet -ListAvailable) -and
7575
$null = Get-PackageProvider -Name NuGet -ErrorAction Stop
7676
}
7777
catch {
78-
Install-PackageProvider -Name Nuget -RequiredVersion 2.8.5.201 -Scope CurrentUser -Force -Confirm:$false
78+
try {
79+
Install-PackageProvider -Name Nuget -RequiredVersion 2.8.5.201 -Scope CurrentUser -Force -Confirm:$false -ErrorAction Stop
80+
}
81+
catch {
82+
Write-Host "##vos[task.logissue type=warning]Falling back to version of Pester shipped with extension. To use a newer version please update the version of PowerShellGet available on this machine."
83+
Import-Module "$PSScriptRoot\4.6.0\Pester.psd1" -force
84+
}
7985
}
8086
$NewestPester = Find-Module -Name Pester | Sort-Object Version -Descending | Select-Object -First 1
8187
If ((Get-Module Pester -ListAvailable | Sort-Object Version -Descending| Select-Object -First 1).Version -lt $NewestPester.Version) {

0 commit comments

Comments
 (0)