pester / AzureDevOpsExtension

MIT License
27 stars 14 forks source link

Errors are thrown, when Pestermodule is not installed locally #18

Closed DOliana closed 4 years ago

DOliana commented 4 years ago

Where are you running it?

Version of Extension/Task

9.1.10

Expected behaviour and actual behaviour

Pester task runs without throwing errors even when it is not able to check for updates or find Pester installed locally - in my understanding it should use the builtin executable. Actual behaviour: The tests are run, but errors are thrown, which causes the task to fail even if all tests were successsful. Logs:

2020-05-08T16:46:58.0927609Z ##[section]Starting: Pester Test Runner
2020-05-08T16:46:58.1110758Z ==============================================================================
2020-05-08T16:46:58.1110850Z Task         : Pester Test Runner
2020-05-08T16:46:58.1110964Z Description  : Run Pester tests by either installing the latest version of Pester at run time (if possible) or using the version shipped with the task (4.6.0)
2020-05-08T16:46:58.1111085Z Version      : 9.1.10
2020-05-08T16:46:58.1111125Z Author       : Pester
2020-05-08T16:46:58.1111173Z Help         : Version: #{Build.BuildNumber}#. [More Information](https://github.com/pester/AzureDevOpsExtension)
2020-05-08T16:46:58.1111242Z ==============================================================================
2020-05-08T16:46:58.3870412Z Using executable 'powershell.exe'
2020-05-08T16:46:58.3871527Z powershell.exe D:\development20181\_work\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.1.10\Pester.ps1 -scriptFolder D:\development20181\_work\r1\a\XXX\Infrastructure\PsTools\RiStatus.Tests.ps1 -resultsFile D:\development20181\_work\r1\a\PesterRiTest.XML -run32Bit false
2020-05-08T16:46:59.2709271Z scriptFolder D:\development20181\_work\r1\a\XXX\Infrastructure\PsTools\RiStatus.Tests.ps1
2020-05-08T16:46:59.2710870Z resultsFile D:\development20181\_work\r1\a\PesterRiTest.XML
2020-05-08T16:46:59.2710954Z run32Bit false
2020-05-08T16:46:59.2711086Z additionalModulePath 
2020-05-08T16:46:59.2711211Z tag 
2020-05-08T16:46:59.2711306Z ExcludeTag 
2020-05-08T16:46:59.2712138Z CodeCoverageOutputFile 
2020-05-08T16:46:59.2712252Z CodeCoverageFolder 
2020-05-08T16:46:59.2712369Z ScriptBlock 
2020-05-08T16:47:02.1602366Z WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»
2020-05-08T16:47:02.1608485Z WARNING: Unable to download the list of available providers. Check your internet connection.
2020-05-08T16:47:11.7519408Z WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
2020-05-08T16:47:11.8843233Z ##[error]PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'Pester'. Try 
2020-05-08T16:47:11.8853626Z ##[error]PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'Pester'. Try 
2020-05-08T16:47:11.8872961Z ##[error]Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.1\PSModule.psm1:8845 char:3
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio 
   n
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
2020-05-08T16:47:11.8875102Z ##[error]Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.1\PSModule.psm1:8845 char:3
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio 
   n
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
2020-05-08T16:47:13.7019084Z Running in AMD64 PowerShell
2020-05-08T16:47:13.7028660Z Running Pester from the folder [D:\development20181\_work\r1\a\XXX\Infrastructure\PsTools\RiStatus.Tests.ps1] output sent to [D:\development20181\_work\r1\a\PesterRiTest.XML]
2020-05-08T16:47:13.9829537Z Pester v4.10.1

Steps to reproduce the problem

Have it run without throwing errors.

ChrisLGardner commented 4 years ago

I've just published 9.1.16 that should have a fix in it for this. Can you let me know if you are still seeing this issue?

DOliana commented 4 years ago

Thanks for the quick response! Please allow for some time since we are facing issues with out build system. If you like you can close this issue and I will come back if the issue is still there after we fix our systems.

jhampson-dbre commented 4 years ago

Hello, we are getting errors as well during the package discovery phase. We just want to use the shipped version of Pester 4.10.1 Azure DevOps Server Version Dev17.M153.3

##[section]Starting: Pester Test Runner
==============================================================================
Task         : Pester Test Runner
Description  : Run Pester tests by either installing the latest version of Pester at run time (if possible) or using the version shipped with the task (4.10.1)
Version      : 9.2.0
Author       : Pester
Help         : Version: #{Build.BuildNumber}#. [More Information](https://github.com/pester/AzureDevOpsExtension)
==============================================================================
Using executable 'powershell.exe'
powershell.exe E:\Agents\04\_work\_tasks\Pester_cca5462b-887d-4617-bf3f-dcf0d3c622e9\9.2.0\Pester.ps1 -scriptFolder @{Path='E:\Agents\04\_work\638\s/azuresql.template.tests.ps1'; Parameters=@{ResourceGroupName='***'; ServicePrincipalPassword='***'; SubscriptionId=***'; ApplicationId='***'; TenantId='***'; TemplatePath='E:\Agents\04\_work\638\s/'}} -resultsFile E:\Agents\04\_work\638\s/azuresql.template.tests.XML -run32Bit False
scriptFolder System.Collections.Hashtable

resultsFile E:\Agents\04\_work\638\s/azuresql.template.tests.XML

run32Bit False

additionalModulePath 

tag 

ExcludeTag 

CodeCoverageOutputFile 

CodeCoverageFolder 

ScriptBlock 

WARNING: MSG:UnableToDownload 
«https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»

WARNING: Unable to download the list of available providers. Check your 
internet connection.

WARNING: Unable to resolve package source 
'https://www.powershellgallery.com/api/v2'.

##[error]PackageManagement\Find-Package : No match was found for the specified search 
criteria and module name 'Pester'. Try Get-PSRepository to see all available 

##[error]PackageManagement\Find-Package : No match was found for the specified search 
criteria and module name 'Pester'. Try Get-PSRepository to see all available 

##[error]registered module repositories.
At C:\Program 
Files\WindowsPowerShell\Modules\PowerShellGet\2.2.3\PSModule.psm1:8873 char:9
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPacka 
   ge:FindPackage) [Find-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.Pac 
   kageManagement.Cmdlets.FindPackage

##[error]registered module repositories.
At C:\Program 
Files\WindowsPowerShell\Modules\PowerShellGet\2.2.3\PSModule.psm1:8873 char:9
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPacka 
   ge:FindPackage) [Find-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.Pac 
   kageManagement.Cmdlets.FindPackage

Running in AMD64 PowerShell

Running Pester using the script parameter [
Name                           Value                                           
----                           -----                                           
Path                           E:\Agents\04\_work\638\s/azuresql.template.te...
Parameters                     {ServicePrincipalPassword, ApplicationId, Res...

] output sent to [E:\Agents\04\_work\638\s/azuresql.template.tests.XML]

Pester v4.10.1
Executing all tests in 'E:\Agents\04\_work\638\s/azuresql.template.tests.ps1'

Executing script E:\Agents\04\_work\638\s/azuresql.template.tests.ps1

  Describing Template validation

    [+] template passes validation check
 2.68s

Tests completed in 5.3s

Tests Passed: 1, 
Failed: 0, 
Skipped: 0, 
Pending: 0, 
Inconclusive: 0 

Pester Script finished
##[section]Finishing: Pester Test Runner

As you can see, we have 1 test and it passes, but the task fails with errors image

ChrisLGardner commented 4 years ago

Looks like the try/catch around those calls isn't handling everything. I'll see what I can do about fixing that at the weekend, or if you want to put in a PR to fix it then I can probably review that sooner.

jhampson-dbre commented 4 years ago

As a temporary workaround, I have set "Continue on error" option on the Pester task, and set "Fail if there are test failures" option on the Publish Test Results task. This allows it to get through the rest of the pipeline (unless there are legitimate test failures), but the overall build status is "Successful with issues".

I'll take a look at the code and see if I may be able to put a PR in for a fix.