【发布时间】:2020-04-24 11:16:50
【问题描述】:
我有以下情况:
- 本地 Azure DevOps 服务器 2019。
- 在 (1) 中发布到 Azure Artifacts 的内部 Powershell 模块。
- docker 容器需要从 (2) 安装模块。
我可以从容器中 curl 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
但我无法从中安装模块:
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>
$credential 对象包含 PAT 作为密码,但由于我无法指定空用户名,所以我改为使用“a”。但这似乎并不重要。
所以,我不明白在容器内运行时如何从 Azure Artifacts 安装 Powershell 模块。有可能吗?
附言
我使用的是 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
test.ps1 在哪里:
Get-ChildItem /certificates | ForEach-Object {
$null = Import-Certificate -FilePath $_.FullName -CertStoreLocation Cert:\LocalMachine\Root
}
编辑 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>
编辑 2
有一个重要的细节我忘了提及 - 我想使用 PAT 进行身份验证。
【问题讨论】:
-
请原谅我对基础的质疑,但是您检查过容器和 Azure DevOps Server 是否可以相互通信吗?即它们是在同一个网络上还是通过互联网公开访问,是否打开/转发了必要的端口(443?)?您可以通过简单的 ping / HTTP GET 与服务器通信吗?
-
是的,我做到了。请注意,在帖子的开头,我将 url 卷曲以表明容器可以成功到达 Tfs 中的 nuget repo。它在帖子中。
-
当您运行 Get-PSRepository 时会发生什么,您的存储库是否显示为 nuget 的 OneGetProvider?另外你为什么使用 v2 端点和 v3?
-
v2 端点是访问 nuget 存储库以获取 powershell 模块时必须使用的端点。
标签: powershell docker tfs azure-devops