Using $ConfirmPreference throws exception when run inside Windows Server Container #121
Description
Problem Overview
We're trying to register an internal / private NuGet PowerShell module repository inside of a Windows Server Container. When we attempt to register the repository, an exception is thrown. Commenting out $ConfirmPreference line in the script that runs insider Windows Server Container resolves the issue
Expected Behavior
Container builds successfully, without errors.
Current Behavior
Set-Variable : Object reference not set to an instance of an object.
At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.1.2.0\PSModule.psm1:4077
char:13
-
Set-Variable -Name selectedProviderName -value $null -Sco ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Set-Variable], NullReferenceE
xception - FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShe
ll.Commands.SetVariableCommand
- CategoryInfo : NotSpecified: (:) [Set-Variable], NullReferenceE
PackageManagement\Register-PackageSource : Unhandled Exception - Message:'One
or more errors occurred.' Name:'AggregateException' Stack Trace:' at
System.Threading.Tasks.Task.ThrowIfExceptional(Boolean
includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean
waitCompletionNotification)
at Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource.Proc
essRecordAsync()
at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayCl
ass83_0.b__0()'
At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.1.2.0\PSModule.psm1:4211
char:17
- ... $null = PackageManagement\Register-PackageSource @PSBoundParamete ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (Microsoft.Power...erPackageSo
urce:RegisterPackageSource) [Register-PackageSource], Exception - FullyQualifiedErrorId : UnhandledException,Microsoft.PowerShell.PackageM
anagement.Cmdlets.RegisterPackageSource
- CategoryInfo : InvalidOperation: (Microsoft.Power...erPackageSo
Steps to Reproduce (for bugs)
- Create a Dockerfile based on microsoft/windowsservercore
- Run Register-PSRepository command inside Dockerfile
build.cmd
cd "%~dp0"
powershell.exe -Command Save-Module -Name PowerShellGet -Path ./
docker build --tag amazon/redacted --file Dockerfile --no-cache .
Dockerfile
FROM microsoft/windowsservercore
MAINTAINER Trevor Sullivan tsulli@amazon.com
RUN mkdir c:\Amazon
COPY [ "PackageManagement", "c:/Program Files/WindowsPowerShell/Modules/PackageManagement"]
COPY [ "PowerShellGet", "c:/Program Files/WindowsPowerShell/Modules/PowerShellGet"]
COPY redacted.ps1 c:\Amazon
RUN powershell.exe -ExecutionPolicy Bypass -File c:\Amazon\redacted.ps1
ENTRYPOINT powershell
redacted.ps1
$ConfirmPreference = 'Low'
$VerbosePreference = 'continue'
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.3 -Force
$Parameters = @{
Name = 'customrepo'
SourceLocation = 'http://website.com/'
PublishLocation = 'http://website.com/api/v2/package'
InstallationPolicy = 'Trusted'
PackageManagementProvider = 'NuGet'
}
Register-PSRepository @parameters
Your Environment
Name Value
PSVersion 5.1.14393.693
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.693
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1