【问题标题】:How to install PowerShell module pushed to Azure Artifacts in Pipelines?如何在 Pipelines 中安装推送到 Azure Artifacts 的 PowerShell 模块?
【发布时间】:2021-01-05 19:03:15
【问题描述】:

this article 之后,我设置了管道以将 PowerShell 模块推送到我的 Artifacts 源。

我可以在本地机器上安装该模块,但我想知道如何在 Pipelines 中做同样的事情?添加 NuGet 源似乎是一个交互过程,那么 Pipelines 如何将 Artifacts 源添加为源?

问题是我不想在 CI 环境中进行任何用户交互。

【问题讨论】:

    标签: powershell azure-devops azure-pipelines azure-artifacts


    【解决方案1】:

    如果您使用的是自托管代理,则需要配置文件夹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

    这是一个认证问题,如果我们改变认证方式,也许我们不需要输入代码。

    另外,我们也可以通过cmdInstall-Module Get-Hello -Scope CurrentUser -Force安装模块

    【讨论】:

    • 感谢您的回答。实际上我已经做到了这一点,但是这个进入浏览器并输入代码的过程,我需要多久执行一次?这会带来管道停滞的风险,因为需要用户输入才能继续。
    • 您好,我已经更新了答案,请检查更新1,然后在这里分享结果。
    • 嗨@iTiamo,刚刚签到看看这个问题现在是否仍然阻碍你?这个问题有什么更新吗?
    • 我在以下博文中找到了解决问题的方法。简而言之:使用 PowerShellGet 模块版本 3.0.0(目前处于测试阶段),我们可以跳过设备代码流并以非交互方式安装 PowerShell 模块。 pipehow.tech/new-psrepository/#avoiding-the-device-code
    猜你喜欢
    • 2021-07-10
    • 2020-04-24
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 2020-07-31
    • 1970-01-01
    • 2020-11-06
    • 1970-01-01
    相关资源
    最近更新 更多