如何修复因错误而失败的Azure-Powershell“ hello world”任务:找不到模块:版本为“ 6.2.3”的“ Az.Accounts”

时间:2019-09-28 08:51:34

标签: azure-devops azure-powershell

我正在建立一个Azure devops管道,我要在其中操纵订阅中的资源。为此,我尝试使用AzurePowerShell任务。

我将尝试简化为一个与订阅有关的最基本的hello world示例:

pool:
  vmImage: windows-2019
trigger: none

steps:
- task: AzurePowerShell@4
  displayName: 'hello world'
  inputs:
    azureSubscription: 'azure-connection-dev'
    azurePowerShellVersion: '6.2.3'
    inline: |
      Write-Output "Hello"
      Write-Output "world"

当我触发该管道时,我希望该管道打印“ Hello world”,但会失败并显示

==============================================================================
Task         : Azure PowerShell
Description  : Run a PowerShell script within an Azure environment
Version      : 4.157.4
Author       : Microsoft Corporation
Help         : [Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613749)
==============================================================================
##[error]Could not find the modules: 'Az.Accounts' with Version: '6.2.3'. If the module was recently installed, retry after restarting the Azure 

上面的hello world示例出了什么问题?

1 个答案:

答案 0 :(得分:0)

错误消息明确告诉您确切问题:托管代理上没有Az 6.2.3。可用的版本为documented。如果您需要默认未安装的版本,则需要首先使用Install-Module进行安装。

Azure Powershell任务通过使用指定的服务连接登录到Azure订阅开始。由于您告诉它使用的版本不可用,因此它正在尝试加载模块并立即失败。