【问题标题】:PowerShell Install-Module Command fails in Azure DevOps PipelineAzure DevOps Pipeline 中的 PowerShell 安装模块命令失败
【发布时间】:2020-10-31 09:15:00
【问题描述】:

在执行管道时,我有以下 PowerShell cmdlet 来安装 PowerShell 模块

steps:
    - powershell: |
    
        Install-PackageProvider Nuget -Scope CurrentUser -Force
        Install-module PSScriptAnalyzer -force -Scope CurrentUser
        Install-module PSPesterTest -force -Scope CurrentUser
      displayName: 'Install required PowerShell modules'

但这会引发"No repository with the name 'PSGallery' was found" 的错误。 请任何人指出有关此问题的解决方法?

【问题讨论】:

    标签: azure azure-devops azure-powershell


    【解决方案1】:

    您的脚本语法有一些问题,请尝试以下脚本:

    pool:
      vmImage: 'windows-2019'
    
    steps:
    
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
          Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
          Install-Module -Name PSPesterTest -Force -Scope CurrentUser
    

    这里是官方document,可以参考。

    【讨论】:

      【解决方案2】:

      编辑

      Install-module 应该是 Install-Module。 此外,通过将 PSRespository 恢复为默认值,您的问题有望得到解决:)

      Register-PSRepository -Default
      

      【讨论】:

        猜你喜欢
        • 2020-12-29
        • 1970-01-01
        • 2017-11-14
        • 1970-01-01
        • 1970-01-01
        • 2019-08-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多