PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

Cannot publish module using `Publish-PSResource` to Azure Artifacts Nuget v3 feed

Open PalmEmanuel opened this issue 2 years ago • 6 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest released version
  • [X] Search the existing issues.

Steps to reproduce

I'm having trouble publishing a module to an Azure Artifacts feed. I've tried various combinations of authentication, but I end up with the error Publish-PSResource: Unable to load the service index for source https://pkgs.dev.azure.com/<org>/<project>/_packaging/MyFeed/nuget/v3/index.json..

I've tried both with the -Credential parameter on Publish-PSResource and with -CredentialInfo on Register-PSResourceRepository as specified in the blog post, but I'm starting to think that Azure Artifacts is a different case since it does not use an API key.

I expected it to work with 3.0-beta14 and the credential / authentication improvements, is it not supported yet in PowerShellGet 3.0?

Expected behavior

PS> Import-Module PowerShellGet -MaximumVersion 3.*
PS> $FeedUrlv3 = 'https://pkgs.dev.azure.com/<org>/<project>/_packaging/MyFeed/nuget/v3/index.json'
PS> Register-PSResourceRepository -Name 'MyRepo' -Uri $FeedUrlv3
PS> Publish-PSResource -Path ".\MyModule\" -Repository MyRepo -SkipDependenciesCheck -Credential $Credential # Credential is pscredential with email as username and PAT for password.

Actual behavior

PS> Import-Module PowerShellGet -MaximumVersion 3.*
PS> $FeedUrlv3 = 'https://pkgs.dev.azure.com/<org>/<project>/_packaging/MyFeed/nuget/v3/index.json'
PS> Register-PSResourceRepository -Name 'MyRepo' -Uri $FeedUrlv3
PS> Publish-PSResource -Path ".\MyModule\" -Repository MyRepo -SkipDependenciesCheck -Credential $Credential

`Publish-PSResource: Unable to load the service index for source https://pkgs.dev.azure.com/<org>/<project>/_packaging/MyFeed/nuget/v3/index.json.`

Error details

Exception             : 
    Type    : System.ArgumentException
    Message : Unable to load the service index for source https://pkgs.dev.azure.com/<org>/<project>/_packaging/MyFeed/nuget/v3/index.json.
    HResult : -2147024809
CategoryInfo          : InvalidResult: (:) [Publish-PSResource], ArgumentException
FullyQualifiedErrorId : PushNupkgError,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource
InvocationInfo        : 
    MyCommand        : Publish-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 53
    Line             : Publish-PSResource -Path ".\MyModule\" -Repository MyRepo -SkipDependenciesCheck -Credential $Credential
    PositionMessage  : At line:1 char:1
                       + Publish-PSResource -Path ".\MyModule\" -Repository MyRepo …
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Publish-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.2.5                 PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability…}
Binary     3.0.14     beta14     PowerShellGet                       {Find-PSResource, Get-PSResource, Get-PSResourceRepository, Install-PSResource…}

Key   : PSVersion
Value : 7.2.4
Name  : PSVersion


Key   : PSEdition
Value : Core
Name  : PSEdition


Key   : GitCommitId
Value : 7.2.4
Name  : GitCommitId


Key   : OS
Value : Microsoft Windows 10.0.19044
Name  : OS


Key   : Platform
Value : Win32NT
Name  : Platform


Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0…}
Name  : PSCompatibleVersions


Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion


Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion


Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion

Visuals

No response

PalmEmanuel avatar Jun 01 '22 13:06 PalmEmanuel

Thanks @PalmEmanuel for the bug report! We will need to support additional credential types for Publish...the Credential Persistence feature is specific to read access, however it is not nearly as useful if publish functionality isnt possible 😄

SydneyhSmith avatar Jun 02 '22 18:06 SydneyhSmith

@PalmEmanuel - Try registering your PSRepository w/ a v2 URL

SourceLocation: https://pkgs.dev.azure.com/<org>/<project>/_packaging/MyFeed/nuget/v2

PublishLocation/ScriptPublishLocation: https://pkgs.dev.azure.com/<org>/<project>/_packaging/MyFeed/nuget/v2/

It's maddening, I found it only after banging my head on it for a couple days and buried in various blog posts/github issues like this, but (for me) it works.

OranguTech avatar Jul 01 '22 15:07 OranguTech

@PalmEmanuel - Try registering your PSRepository w/ a v2 URL

SourceLocation: https://pkgs.dev.azure.com/<org>/<project>/_packaging/MyFeed/nuget/v2

PublishLocation/ScriptPublishLocation: https://pkgs.dev.azure.com/<org>/<project>/_packaging/MyFeed/nuget/v2/

It's maddening, I found it only after banging my head on it for a couple days and buried in various blog posts/github issues like this, but (for me) it works.

That's correct for PowerShellGet 2.* (which I assume you're using since you specify two parameters), but the pre-release version 3 is supposed to support v3 feeds too. Good catch though if someone finds this issue and wants a solution for the current release 👍

PalmEmanuel avatar Jul 01 '22 16:07 PalmEmanuel

Whoops @PalmEmanuel , you're correct, sorry I missed that rather important detail.

@SydneyhSmith - the not-well-documented and difficulty of publishing modules to a custom Azure DevOps artifacts feed is an ongoing issue. Please consider making Powershell(Get) a first-class citizen in the Artifacts "Connect to feed" page (alongside Nuget/Visual Studio/Dotnet), and thoroughly test the documentation/steps to allow Register-PSResourceRepository and Publish-PSResource to work with AzDOS artifact feeds, preferably with multiple authentication options, including user Credentials, PATs, webflow, etc.

OranguTech avatar Jul 01 '22 20:07 OranguTech

I am having the same problem while trying to use the NuGet package registry in GitLab. GitLab does not support v2.

ayancey avatar Aug 09 '22 23:08 ayancey

I'm experiencing the same problem trying to use AWS's CodeArtifact which only supports v3.

tomcart90 avatar Aug 31 '22 11:08 tomcart90