PowerShell安装模块命令在Azure DevOps管道中失败

时间:2020-10-31 09:15:00

标签: azure azure-devops azure-powershell

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

func xappend(orig []int, add []int) []int {
    has := len(orig)
    needed := has + len(add)
    // If we can fit the added elements in, do that now.
    if cap(orig) >= needed {
        fmt.Println("copy in place")
        orig = orig[:needed]
        copy(orig[has:needed], add)
        return orig
    }
    newSize := undocumentedFunction(has, cap(orig), needed)
    fmt.Println("make new, size", newSize)
    new := make([]int, needed, newSize)
    copy(new, orig)
    copy(new[has:needed], add)
    return new
}

func undocumentedFunction(oldCap, oldLen, newCap int) int {
    twiceAsMuch := oldCap + oldCap
    if newCap > twiceAsMuch {
        return newCap
    }
    // 2x old capacity is enough, but
    // we'll tweak this in various ways.
    // The exact tweaks might change at any time.
    if oldLen < 1024 {
        return twiceAsMuch
    }
    panic("didn't copy this part")
}

这将引发错误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' 。 拜托,任何人都可以针对这个问题为我指出解决方法吗?

2 个答案:

答案 0 :(得分:0)

编辑

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

Register-PSRepository -Default

答案 1 :(得分:0)

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

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

enter image description here

这里是您可以参考的官方document