[英]How to install a powershell module within a docker container from an on-prem Azure Artifacts repository using PAT?
I have the following situation:我有以下情况:
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 .您还可以在此处查看详细示例。
确认为 Azure DevOps 2019 中的错误 - https://developercommunity.visualstudio.com/comments/885584/view.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.