PowerShell 安装模块命令在 Azure DevOps 管道中失败
PowerShell Install-Module Command fails in Azure DevOps Pipeline
我有以下 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"
错误。
任何人都可以指出有关此问题的解决方法吗?
编辑:
Install-module
应该是 Install-Module
。
此外,通过将 PSRespository 恢复为默认值,您的问题有望得到解决:)
Register-PSRepository -Default
您的脚本语法有问题,请尝试以下脚本:
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你可以参考
我有以下 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"
错误。
任何人都可以指出有关此问题的解决方法吗?
编辑:
Install-module
应该是 Install-Module
。
此外,通过将 PSRespository 恢复为默认值,您的问题有望得到解决:)
Register-PSRepository -Default
您的脚本语法有问题,请尝试以下脚本:
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你可以参考