自承载代理 Azure PowerShell (核心) - 找不到模块



我在Azure DevOps中运行一个自托管Windows Agent。我已经安装了PowerShell Core 6.2.3,并且作为管理员安装了Az模块,以便所有用户都可以使用它。

当我使用 Azure PowerShell任务 (V4( 运行生成时 - 标记为"使用 PowerShell 核心"和 Azure PowerShell 的"最新版本"时,我收到以下消息:

==============================================================================
Task         : Azure PowerShell
Description  : Run a PowerShell script within an Azure environment
Version      : 4.159.3
Author       : Microsoft Corporation
Help         : [Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613749)
==============================================================================
Added TLS 1.2 in session.
Disconnect-AzureRmAccount -Scope Process -ErrorAction Stop
##[warning]Run Connect-AzureRmAccount to login.
##[error]Could not find the modules: 'Az.Accounts' with Version: ''. If the module was recently installed, retry after restarting the Azure Pipelines task agent.

如果我在托管代理上运行脚本,它工作正常。我无法弄清楚为什么它失败了。我假设在运行构建代理的配置文件或环境中有所不同 - 但我不确定如何检查这一点。

在构建代理上,如果我打开 PSCore 窗口并运行:

Get-Module Az -ListAvailable

它正确找到模块。

DevOps 代理很可能以其他用户身份运行,并且尚未为该用户安装 Az 模块。假设代理作为服务运行,可以通过运行services.msc来检查用户,并查找"Azure 管道代理"、"VSTS 代理"或"vstsagent"。[组织名称]。[代理名称]" [1]。

运行Get-Module Az -ListAvailable以查看模块的安装位置。C:Program FilesPowerShellModules下的模块已为所有用户安装 [2]。

您可以使用以下方法为所有用户安装模块:

Install-Module -Name Az -Scope AllUsers

[1] https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops#run-as-a-service

[2] https://learn.microsoft.com/en-us/powershell/module/powershellget/install-module?view=powershell-7.1#parameters

相关内容

最新更新