gsscoder
gsscoder

Reputation: 3392

Azure: PowerShell module properly pushed to artifacts feed repository cannot be installed

My purpose is to configure a private feed for being able to use my PowerShell modules inside Azure Pipelines.

I've followed step by step this Microsoft guide: https://learn.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops.

I know the package was properly pushed from DevOps UI: enter image description here

Following code (executed from my development machine) proofs that both feed and package are in valid state:

$patToken = "**************************************" | ConvertTo-SecureString -AsPlainText -Force
$credsAzureDevopsServices = New-Object System.Management.Automation.PSCredential("[email protected]", $patToken)
Get-PSRepository
Find-Module -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices
Install-Module -Name Get-Hello -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices

This is the output:

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2
PowershellAzureDevopsS... Trusted              https://pkgs.dev.azure.com/dev4side/Dev4side%20-%20Intranet.ai/_packaging/iai-feed/nuget/v2

Name                       : Get-Hello
Version                    : 1.0.0
Type                       : Module
Description                : Package description
Author                     : dev4side
CompanyName                :
Copyright                  : Copyright 2020 Dev4Side SRL
PublishedDate              : 4/1/2020 11:28:48 AM
InstalledDate              :
UpdatedDate                :
LicenseUri                 :
ProjectUri                 : 
IconUri                    :
Tags                       : {devtest}
Includes                   : {Function, RoleCapability, Command, DscResource...}
PowerShellGetFormatVersion :
ReleaseNotes               : Summary of changes made in this release of the package.
Dependencies               : {}
RepositorySourceLocation   : https://pkgs.dev.azure.com/dev4side/Dev4side%20-%20Intranet.ai/_packaging/iai-feed/nuget/v2
Repository                 : PowershellAzureDevopsServices
PackageManagementProvider  : NuGet
AdditionalMetadata         : @{summary=Package description; releaseNotes=Summary of changes made in this release of the package.; copyright=Copyright      
                             2020 Dev4Side SRL; tags=devtest; PackageManagementProvider=NuGet; SourceName=PowershellAzureDevopsServices;
                             description=Package description; created=4/1/2020 11:28:48 AM +02:00; published=4/1/2020 11:28:48 AM +02:00;
                             developmentDependency=False; NormalizedVersion=1.0.0; downloadCount=0; lastUpdated=4/1/2020 11:28:48 AM +02:00;
                             Authors=dev4side; updated=2020-04-01T09:28:48Z; isLatestVersion=True; Listed=true; IsPrerelease=false;
                             isAbsoluteLatestVersion=True; packageSize=15279; lastEdited=4/1/2020 11:28:48 AM +02:00; requireLicenseAcceptance=False}     

But if I try to install the module (using Administrator account) with:

Install-Module -Name Get-Hello -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices

I get:

PackageManagement\Install-Package : Unable to resolve package source 'https://pkgs.dev.azure.com/dev4side/Dev4side -
Intranet.ai/_packaging/iai-feed/nuget/v2'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.3\PSModule.psm1:9685 char:34
+ ... talledPackages = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (https://pkgs.de...i-feed/nuget/v2:String) [Install-Package], Exceptio
   n
    + FullyQualifiedErrorId : UnableToResolveSource,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

In this gist there's the list of my installed modules.

I want to add that:

nuget install Get-Hello

perfectly works:

Feeds used:
  https://api.nuget.org/v3/index.json
  https://pkgs.dev.azure.com/dev4side/Dev4side%20-%20Intranet.ai/_packaging/iai-feed/nuget/v3/index.json
  C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Installing package 'Get-Hello' to 'C:\Temp'.
  GET https://api.nuget.org/v3/registration5-gz-semver2/get-hello/index.json
  NotFound https://api.nuget.org/v3/registration5-gz-semver2/get-hello/index.json 529ms
  GET https://pkgs.dev.azure.com/dev4side/eef92fe2-7e7f-4eb5-a62c-cc1dc2f2b440/_packaging/930b7fe7-4c85-435a-9945-733a3
0e1ea5b/nuget/v3/registrations2-semver2/get-hello/index.json
  OK https://pkgs.dev.azure.com/dev4side/eef92fe2-7e7f-4eb5-a62c-cc1dc2f2b440/_packaging/930b7fe7-4c85-435a-9945-733a30
e1ea5b/nuget/v3/registrations2-semver2/get-hello/index.json 1501ms


Attempting to gather dependency information for package 'Get-Hello.1.0.0' with respect to project 'C:\Temp', targeting
'Any,Version=v0.0'
Gathering dependency information took 26.03 ms
Attempting to resolve dependencies for package 'Get-Hello.1.0.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Get-Hello.1.0.0'
Resolved actions to install package 'Get-Hello.1.0.0'
Retrieving package 'Get-Hello 1.0.0' from 'PowershellModules'.
Adding package 'Get-Hello.1.0.0' to folder 'C:\Temp'
Added package 'Get-Hello.1.0.0' to folder 'C:\Temp'
Successfully installed 'Get-Hello 1.0.0' to C:\Temp
Executing nuget actions took 119.62 ms

Any help REALLY appreciated!

Upvotes: 5

Views: 1520

Answers (2)

Marco Borm
Marco Borm

Reputation: 141

There is a bug in some of the PackageManagement or PowerShellGet component for years, that exactly cause this issue. I had the same issue and can verify that its correctly working if you register the repository as PowerShell repository and as a package source. The error message I got using the latest PackageManager 2.2.4.1 is nearly identical, I just adding it here to help other people find this exact message:

C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.4.1\PSModule.psm1:9709 Zeichen:34

So:

Register-PSRepository -Name DevOpsFeedPsRepo [...] -SourceLocation $artifactFeed
Register-PackageSource -Name DevOpsFeedPackageSource -Location "$artifactFeed" -ProviderName NuGet -SkipValidate 

I can also confirm that using the Azure Artifacts Credential Provider there is no need to give the credentials all the time after first registration.

Upvotes: 14

Tonino Bruno
Tonino Bruno

Reputation: 13

I was having the same problem, but I found a blog post which went through the same troubleshooting process and came to the conclusion that without providing the PAT code during the Install-Module it won't be able to authenticate to the feed and download the package.

I did this in my tests and it worked:

Install-Module -Repository PSModules -Name Get-Hello -Credentials $PSCredwithPAT

It would be great if this worked with the embedded credentials on the PowerShell Repository we registered. But without that, this appears to be the best solution.

Upvotes: 1

Related Questions