运行 AzurePowershell@5 任务时出现“无法找到模块:带有版本的‘Az.Accounts’”错误

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

我正在使用 AzurePowershell@5 任务运行 powershell 脚本,该脚本将构建模板规范并将其推送到资源组。我正在使用 azurerm 服务连接进行身份验证。这是任务详细信息:

- task: AzurePowershell@5
            displayName: Template Spec Generation
            inputs:
              azureSubscription: 'azurerm service principal'
              scriptType: filePath
              scriptPath: $(Build.SourcesDirectory)\src\sxript.ps1
              scriptArguments:
                -resourceGroupName <name> `
                -location eastus `
                -overrideVersion true `
                -isTagged true `
                -tag test `
                -outputPath output.json
              azurePowerShellVersion: latestVersion
              pwsh: true

但是我在运行此任务时遇到以下错误:

##[错误]找不到模块:“Az.Accounts”,版本:“”。如果最近安装了该模块,请重新启动 Azure 后重试 管道任务代理。 ##[错误]PowerShell 退出,代码为“1”。

有人可以帮忙吗?

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

当我使用自托管代理时,我可以重现相同的问题。

问题的原因可能是代理计算机上尚未安装 Az 模块。

要解决此问题,您需要导航到代理所在的计算机并运行以下命令来安装 Az 模块。

Install-Module -Name Az -Scope AllUsers -AllowClobber

然后您可以重新启动自托管代理并再次运行管道。

对于 Microsoft 托管的 Agent,Az 模块已预安装在 Agent 计算机上。您可以运行命令:

Get-Module Az -ListAvailable
来检查Microsot托管的Agent中安装的模块。

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