簡體   English   中英

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" 請任何人都可以為我指出有關此問題的解決方法嗎?

您的腳本語法有問題,請嘗試以下腳本:

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

在此處輸入圖片說明

這里是官方文檔,大家可以參考。

編輯

Install-module應該是Install-Module 此外,通過將 PSRespository 恢復為默認值,您的問題有望得到解決:)

Register-PSRepository -Default

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM