test-kitchen / kitchen-pester

A Test Kitchen driver to execute Pester as a verifier

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error running `Set-ExecutionPolicy` causes the kitchen-pester runner to fail

vexx32 opened this issue · comments

Whether or not this appears may depend on the specific box / instance being used. I'm seeing it appear on Windows 2019 images in AWS as I run tests.

When this occurs, kitchen-pester seems completely unable to retrieve test XML files.
Full error text:

$$$$$$ set-executionpolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by 
$$$$$$ a policy defined at a more specific scope.  Due to the override, your shell will retain its current effective 
$$$$$$ execution policy of Bypass. Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more 
$$$$$$ information please see "Get-Help Set-ExecutionPolicy".
$$$$$$ At C:\windows\temp\winrm-elevated-shell-0be7c546-7efa-471c-ac96-3376ee8feb9f.ps1:2 char:1
$$$$$$ + set-executionpolicy unrestricted -force;
$$$$$$ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$$$$$$     + CategoryInfo          : PermissionDenied: (:) [Set-ExecutionPolicy], SecurityException
$$$$$$     + FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand

Best fix here is to simply catch the unhandled exception and emit a warning instead. This error does not necessarily mean the script cannot execute; it simply indicates that the new setting isn't taking effect in the current session. This may prevent the rest of the script(s) running, but it is not in itself a definitive failure.