Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Using $ConfirmPreference throws exception when run inside Windows Server Container #121

Open
@vgangamsft

Description

@vgangamsft

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

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

Steps to Reproduce (for bugs)

  1. Create a Dockerfile based on microsoft/windowsservercore
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions