简体   繁体   English

如何使用 PAT 从本地 Azure Artifacts 存储库在 docker 容器中安装 powershell 模块?

[英]How to install a powershell module within a docker container from an on-prem Azure Artifacts repository using PAT?

I have the following situation:我有以下情况:

  1. On-prem Azure DevOps Server 2019.本地 Azure DevOps Server 2019。
  2. Internal Powershell module published to the Azure Artifacts in (1).在 (1) 中发布到 Azure Artifacts 的内部 Powershell 模块。
  3. A docker container needs to install the module from (2). docker 容器需要从(2)安装模块。

I can curl the Azure Artifacts NuGet repository from within the container:我可以从容器内卷曲 Azure Artifacts NuGet 存储库:

PS C:\azp> $Uri
https://tfs.xyz.com/tfs/DefaultCollection/_packaging/xyz@Release/nuget/v2
PS C:\azp> $headers

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


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

But I cannot install the module from it:但我无法从中安装模块:

PS C:\azp> $Name
xyz
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 'https://tfs.xyz.com/tfs/DefaultCollection/_packaging/xyz@Release/nuget/v2'. Are you missing 'Credential' parameter in the cmdlet?
WARNING: Unable to resolve package source 'https://tfs.xyz.com/tfs/DefaultCollection/_packaging/xyz@Release/nuget/v2'.
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\1.0.0.1\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. $credential对象包含 PAT 作为密码,但由于我无法指定空用户名,所以我改为提供 'a'。 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.因此,我不明白在容器内运行时如何从 Azure Artifacts 安装 Powershell 模块。 Is it possible at all?有可能吗?

PS聚苯乙烯

I am using Windows 10. The base image for the interactive container is created from this docker file:我使用的是 Windows 10。交互式容器的基本映像是从此 docker 文件创建的:

FROM mcr.microsoft.com/windows/servercore:ltsc2019
COPY certificates certificates
WORKDIR /azp
COPY test.ps1 .
COPY Token.txt .token
CMD powershell .\test.ps1

Where test.ps1 is:其中 test.ps1 是:

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

EDIT 1编辑 1

PS C:\azp> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
xyz                       Trusted              http://tfs.xyz.com:8080/tfs/DefaultCollection/_packaging/xyz@Release/nuget/v2
PSGallery                 Trusted              https://www.powershellgallery.com/api/v2


PS C:\azp> Get-PackageProvider

Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
NuGet                    2.8.5.208        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResou...
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent


PS C:\azp>

EDIT 2编辑 2

There is an important detail I forgot to mention - I want to authenticate using PAT.有一个重要的细节我忘了提及 - 我想使用 PAT 进行身份验证。

There is a missing for 'Credential', this error indicates the $credential parameter you passed might be wrong.缺少“凭据”,此错误表明您传递的 $credential 参数可能有误。

The -Credential parameter requires a PSCredential as documented in Install-Module . -Credential参数需要安装模块中记录的PSCredential But from the output of the $credential you posted, we know it is not a pscredential object.但是从您发布的 $credential 的输出中,我们知道它不是一个 pscredential 对象。

Please try below script to create a Pscredential .请尝试下面的脚本来创建一个 Pscredential

$secpasswd = ConvertTo-SecureString "PAT" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential("username", $secpasswd)

Then run Install-Module Command with the pscredential $mycreds然后使用 pscredential $mycreds 运行Install-Module命令

Install-Module @Params @RepoParam -Scope CurrentUser -Credential $mycreds

Please make sure the PAT is valid and have Packaging: Read, write & manage permission.请确保 PAT 是有效的,并且具有包装:读取、写入和管理权限。 You can also check the detailed example here .您还可以在此处查看详细示例。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在管道中安装推送到 Azure 工件的 PowerShell 模块? - How to install PowerShell module pushed to Azure Artifacts in Pipelines? 使用 powershell 将 docker 映像推送到 azure 容器注册表存储库中 - Push docker image into azure container registries repository using powershell 使用 PowerShell CSOM 从 SharePoint On-Prem 获取所有 Web 应用程序 - Get All Web Applications from SharePoint On-Prem using PowerShell CSOM 我如何使用 PowerShell 或 REST 验证 WOPI 是否在本地 OOS 上运行? - How can I validate WOPI is working on OOS on-prem using PowerShell or REST? Azure:无法安装正确推送到工件提要存储库的 PowerShell 模块 - Azure: PowerShell module properly pushed to artifacts feed repository cannot be installed 将本地数据库从本地 SQL Server 上传到 Azure - Uploading local database from SQL Server on-prem to Azure 如何在Azure DevOps构建期间使用PowerShell脚本将构建工件推送到Git存储库? - How to push build artifacts to Git repository using PowerShell script during Azure DevOps build? 如何使用 Azure DevOps Server 2019(本地)中的 Azure 服务连接从发布阶段运行的脚本运行 terraform? - How can one use Azure Service Connection in Azure DevOps Server 2019 (on-prem) to run terraform from a script running in a release stage? Connect-AzAccount Powershell 本地 - Connect-AzAccount Powershell on-prem 如何在 mcr.microsoft.com/powershell 映像之外的 docker 容器中安装 powershell 模块? - How to install powershell modules within a docker container off the mcr.microsoft.com/powershell image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM