Richard Brown
Richard Brown

Reputation: 1

Using a private Azure Devops Artifact feed as a PS Repository

I am using Azure DevOps pipelines to package up some powershell modules into Nuget packages in an artifact feed. From a different computer I then try and register the feed as a PS Repository. It works find for public feeds, but for private feeds I know I need to add a credential on the Register-PSRepository command but it doesn't seem to work. The PAT token I am using for my personal Devops account has full access and is not expired. Here is the code:

$Token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
$EMail = '[email protected]'
$Org = 'thinklogically'
$Project = 'xxxxxx'
$Feed = 'xxxxxxxx'

$patToken = $Token | ConvertTo-SecureString -AsPlainText -Force
$credsAzureDevopsServices = New-Object System.Management.Automation.PSCredential("$EMail", $patToken)

$IsRepo = Get-PSRepository -Name 'MyRepo' -ErrorAction SilentlyContinue
If ($IsRepo) { Unregister-PSRepository -Name MyRepo }

$Params = @{
    Name               = 'MyRepo'
    SourceLocation     = "https://pkgs.dev.azure.com/$Org/$Project/_packaging/$Feed/nuget/v2"
    PublishLocation    = "https://pkgs.dev.azure.com/$Org/$Project/_packaging/$Feed/nuget/v2"
    InstallationPolicy = 'Trusted'
    Credential         = $credsAzureDevopsServices 
}
Register-PSRepository @Params
Get-PSRepository
Find-Module -Repository MyRepo

I get the error:

WARNING: Cannot access 'https://pkgs.dev.azure.com/thinklogically/xxxxxx/_packaging/xxxxxxx/nuget/v2'. Are you missing 'Credential' parameter in the cmdlet? WARNING: Unable to resolve package source 'https://pkgs.dev.azure.com/thinklogically/xxxxxxxx/_packaging/xxxxxxxxxx/nuget/v2'.

I have searched high and low but cannot see what I am doing wrong and wonder if it is a querk/bug.

Upvotes: 0

Views: 749

Answers (1)

Dylan Prins
Dylan Prins

Reputation: 1

Find-Module -Repository MyRepo -Credential $credsAzureDevopsServices.

You will have to specify your credentials every time. I know it's lame.

Upvotes: 0

Related Questions