Azure DevOps 管道由于 MSFT 更新 AZ.Accounts 模块而失败

问题描述 投票:0回答:1

我在今天之前就配置了这条管道并使其工作。但是,根据最近对模块的更新,我现在收到此错误

Console output

Write-Error: This module requires Az.Accounts version 2.19.0. An earlier version of
Az.Accounts is imported in the current PowerShell session. Please open a new
session before importing this module. This error could indicate that multiple
incompatible versions of the Azure PowerShell cmdlets are installed on your
system. Please see https://aka.ms/azps-version-error for troubleshooting
information.

我尝试将其添加到我的模块脚本中以删除现有的并安装新版本 2.19.0。但没有运气

$desiredVersion = "2.19.0"
$installedModule = Get-InstalledModule -Name "Az.Accounts" -ErrorAction SilentlyContinue
Write-Output "$($installedModule)"
if ($installedModule) {
    if ($installedModule.Version.ToString() -ne $desiredVersion) {
        Uninstall-Module -Name "Az.Accounts" -Force -ErrorAction SilentlyContinue
        Install-Module -Name "Az.Accounts" -RequiredVersion $desiredVersion -Force -AllowClobber -Scope CurrentUser -Repository PSGallery
    }
} else {
    Install-Module -Name "Az.Accounts" -RequiredVersion $desiredVersion -Force -AllowClobber -Scope CurrentUser -Repository PSGallery
}
Import-Module Az.Accounts
azure powershell azure-devops
1个回答
0
投票

您可以尝试在 Azure PowerShell 任务之前添加 PowerShell 任务来安装模块

Az.Accounts 2.19.0
。请参阅下面的示例作为参考。

stages:
- stage: A
  jobs:
  - job: A1
    pool:
      vmImage: ubuntu-latest
    steps:
    - task: PowerShell@2
      displayName: 'Install Module Az.Accounts'
      inputs:
        pwsh: true
        targetType: 'inline'
        script: 'Install-Module -Name Az.Accounts -RequiredVersion 2.19.0 -Repository PSGallery -Force'
    
    - task: AzurePowerShell@5
      displayName: 'Check Module Az.Accounts'
      inputs:
        pwsh: true
        azureSubscription: 'myArmConnection'
        ScriptType: 'InlineScript'
        Inline: 'Get-InstalledModule -Name "Az.Accounts"'
        azurePowerShellVersion: 'LatestVersion'

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.