gaelcolas / Sampler

Module template with build pipeline and examples, including DSC elements.
MIT License
171 stars 42 forks source link

Private galleries don't register correctly #430

Open cohdjn opened 1 year ago

cohdjn commented 1 year ago

Problem description

When modifying Resolve-Dependency.psd1 to use a private internal gallery, build.ps1 throws errors because the arguments presented to Register-PSRepository in the splat are wrong.

This is the original splat:

    RegisterGallery = @{
        Name = 'PSProdRepo'
        GallerySourceLocation = 'https://obfuscated.local/nuget/PSProdRepo'
        GalleryPublishLocation = 'https://obfuscated.local/nuget/PSProdRepo'
        GalleryScriptSourceLocation = 'https://obfuscated.local/nuget/PSProdRepo'
        GalleryScriptPublishLocation = 'https://obfuscated.local/nuget/PSProdRepo'
        InstallationPolicy = 'Trusted'
    }

The corrected splat:

    RegisterGallery = @{
        Name = 'PSProdRepo'
        SourceLocation = 'https://obfuscated.local/nuget/PSProdRepo'
        PublishLocation = 'https://obfuscated.local/nuget/PSProdRepo'
        ScriptSourceLocation = 'https://obfuscated.local/nuget/PSProdRepo'
        ScriptPublishLocation = 'https://obfuscated.local/nuget/PSProdRepo'
        InstallationPolicy = 'Trusted'
    }

Verbose logs

[pre-build] Starting Build Init
[pre-build] Dependency missing, running './build.ps1 -ResolveDependency -Tasks noop' for you 

[pre-build] Resolving dependencies.
[pre-build] Starting bootstrap process.
Register-PSRepository : A parameter cannot be found that matches parameter name 'GalleryPublishLocation'.
At C:\PSCodeGallery\Modules\Prod\Snmp\Resolve-Dependency.ps1:263 char:31
+         Register-PSRepository @RegisterGallery
+                               ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Register-PSRepository], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Register-PSRepository

PackageManagement\Get-PackageSource : Unable to find repository 'PSProdRepo'. Use Get-PSRepository to see all available 
repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.4.1\PSModule.psm1:9531 char:35
+ ... ckageSources = PackageManagement\Get-PackageSource @PSBoundParameters
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...etPackageSource:GetPackageSource) [Get-PackageSource], Exception   
    + FullyQualifiedErrorId : SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource

How to reproduce

Uncomment the splat in Resolve-Dependency.psd1 and provide valid arguments but leave the keys as originally coded.

Expected behavior

It should have registered my internal repo.

Current behavior

The build process dies when registering the internal repository.

Suggested solution

Correct the keys in the splat, though I suspect it may not be that simple depending on the varied versions of Powershell.

Operating system the target node is running

sName               : Microsoft Windows 10 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell version and build the target node is running

PSVersion                      5.1.19041.2364
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.2364
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module version used

Sampler 0.116.5 C:\Users\admindjn\Documents\WindowsPowerShell\Modules\Sampler\0.116.5\Sampler.psd1
gaelcolas commented 1 year ago

True! Thanks for spotting, that's a mistake from many years ago... I'd love a PR :)