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

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

我正在建立一个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示例出了什么问题?

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

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

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


-1
投票

尝试写输出“ Hello World”。

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