使用了错误的 Az.Acounts 版本

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

我在管道中执行这些任务时失败了,因为它使用早于 2.19.0 (2.17.0) 的 Az.Accounts 版本

- task: PowerShell@2
  displayName: 'Insatll Az.Accounts'
  inputs:
    pwsh: true
    targetType: 'inline'
    script: 'Install-Module -Name Az.Accounts -RequiredVersion 2.19.0 -Repository PSGallery -Force
- task: AzurePowerShell@5
  displayName: 'Export Cost Datea
  inputs:
    pwsh: true
    azureSubscription: $serviceconnection
    azurePowerShellVersion: LatestVersion
    scriptType: 'inlineScript'
    inline: |
      Update-Module -Name "Az.Accounts" -Force 
      Get-InstalledModule -Name "Az.Accounts"
      Get-Module -ListAvailable
      $azTenantId = (Get-AzContext).Tenant.Id
      Write-host (Get-AzTenant | where-object Id -eq $azTenantId).Name
      Install-Module Az.CostManagement -Scope CurrentUser -Force
      Import-Module Az.CostManagement
      Invoke-AzCostManagementExecuteReport -ExportName $costExport -Scope $scope

本质上它只是调用成本管理导出,所有其他代码只是为了让它工作。当我列出模块时,我可以看到两个版本都已安装。如何使管道使用正确的版本?

我尝试使用此修复Azure Devops 管道因 MSFT 更新 AZ.Accounts 模块而失败,但它不再工作。

我还添加了更新模块 Line,但它也没有工作,并且仍然抛出错误:

此模块需要 Az.Accounts 版本 2.19.0。早期版本的 Az.Accounts 会导入到当前 PowerShell 会话中。请在导入此模块之前打开一个新会话。此错误可能表明您的系统上安装了多个不兼容版本的 Azure PowerShell cmdlet。请参阅 https://aka.ms/azps-version-error 了解故障排除信息。 ##[错误]PowerShell 退出,代码为“1”。

enter image description here

enter image description here

enter image description here

azure azure-devops azure-pipelines azure-powershell
1个回答
0
投票

Az.Accounts
ubuntu-latest
上的
windows-latest
默认版本都是2.17.0。

使用

Install-Module -Name Az.Accounts -RequiredVersion 2.19.0 -Repository PSGallery -Force
安装模块Az.Accounts 2.19.0,无论在我的管道中使用
ubuntu-latest
还是
windows-latest
,它都可以正常工作。

您可以使用

windows-latest
重试并分享错误消息(如果有)。

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