How to install a powershell module within a docker container from an on-prem Azure Artifacts repository?


I have the following situation:

  1. On-prem Azure DevOps Server 2019.
  2. Internal Powershell module published to the Azure Artifacts in (1).
  3. A docker container needs to install the module from (2).

I can curl the Azure Artifacts NuGet repository from within the container:

PS C:\azp> $Uri
PS C:\azp> $headers

Name                           Value
----                           -----
Authorization                  Basic ***

PS C:\azp> (curl $Uri -Headers $headers -UseBasicParsing).StatusCode

But I cannot install the module from it:

PS C:\azp> $Name
PS C:\azp> $credential

UserName                     Password
--------                     --------
a        System.Security.SecureString

PS C:\azp> Register-PSRepository -Name $Name -SourceLocation $Uri -PublishLocation $Uri -InstallationPolicy Trusted -Credential $credential
PS C:\azp> $Params

Name                           Value
----                           -----
Name                           xyz.PS.Core
Force                          True
ErrorAction                    Stop

PS C:\azp> $RepoParam

Name                           Value
----                           -----
Repository                     xyz

PS C:\azp> Install-Module @Params @RepoParam -Scope CurrentUser -Credential $credential
WARNING: Cannot access ''. Are you missing 'Credential' parameter in the cmdlet?
WARNING: Unable to resolve package source ''.
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'xyz.PS.Core'. Try Get-PSRepository to see all available registered
module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\\PSModule.psm1:1809 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

PS C:\azp>

The $credential object contains the PAT as the password, but since I could not specify the empty user name, I give ‘a’ instead. But it does not seem to matter.

So, I do not understand how to install a Powershell module from the Azure Artifacts when running inside a container. Is it possible at all?


I am using Windows 10. The base image for the interactive container is created from this docker file:

COPY certificates certificates
COPY test.ps1 .
COPY Token.txt .token
CMD powershell .\test.ps1

Where test.ps1 is:

Get-ChildItem /certificates | ForEach-Object {
    $null = Import-Certificate -FilePath $_.FullName -CertStoreLocation Cert:\LocalMachine\Root
1 Like