问题描述
在 this article 之后,我设置了管道以将 PowerShell 模块推送到我的 Artifacts 提要。
我可以在本地机器上安装该模块,但我想知道如何在 Pipelines 中执行相同的操作?添加 NuGet 源似乎是一个交互过程,那么 Pipelines 如何将 Artifacts 源添加为源?
问题是我不想在 CI 环境中进行任何用户交互。
解决方法
如果您使用自托管代理,则需要配置文件夹module
权限,自托管代理通过服务帐户而不是个人帐户运行cmd。
如果您使用的是托管代理,请添加任务电源外壳并输入以下脚本以安装模块。
$patToken = "$(pat)" | ConvertTo-SecureString -AsPlainText -Force
$credsAzureDevopsServices = New-Object System.Management.Automation.PSCredential("xxx",$patToken)
Register-PSRepository -Name "PowershellAzureDevopsServices" -SourceLocation "https://pkgs.dev.azure.com/{Org name}/{project name}/_packaging/{feed name}/nuget/v2" -PublishLocation "https://pkgs.dev.azure.com/{Org name}/{project name}/_packaging/{feed name}/nuget/v2" -InstallationPolicy Trusted -Credential $credsAzureDevopsServices
Get-PSRepository
Find-Module -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices
Install-Module -Name Get-Hello -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices
Get-Module -ListAvailable Get-Hello
结果:
更新 1
我们需要在注册电源机箱存储库时输入代码,方法是Register-PSRepository
这是一个认证问题,如果我们改变认证方式,可能就不需要输入验证码了。
此外,我们也可以通过 cmd Install-Module Get-Hello -Scope CurrentUser -Force