Self-Hosted Agent Azure PowerShell (Core) – 模块未找到

huangapple go评论76阅读模式
英文:

Self-Hosted Agent Azure PowerShell (Core) - Module Not Found

问题

I'm running a Self Hosted Windows Agent in Azure DevOps. I have installed PowerShell Core 6.2.3 and as the Administrator installed the Az module so that it is available to all users.

When I run a build using the Azure PowerShell task (V4) - marking as "Use PowerShell Core" and the "Latest Version" of Azure PowerShell I receive the following message:

==============================================================================
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.

If I run the script on a Hosted Agent it works fine. I can't work out why it fails. I assume it is something different in the profile or environment that the build agent runs under - but I'm not sure how to check this.

On the build agent if I open a PSCore window and run:

Get-Module Az -ListAvailable

It finds the module correctly.

英文:

I'm running a Self Hosted Windows Agent in Azure DevOps. I have installed PowerShell Core 6.2.3 and as the Administrator installed the Az module so that it is available to all users.

When I run a build using the Azure PowerShell task (V4) - marking as "Use PowerShell Core" and the "Latest Version" of Azure PowerShell I receive the following message:

==============================================================================
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.

If I run the script on a Hosted Agent it works fine. I can't work out why it fails. I assume it is something different in the profile or environment that the build agent runs under - but I'm not sure how to check this.

On the build agent if I open a PSCore window and run:

Get-Module Az -ListAvailable

It finds the module correctly.

答案1

得分: 1

DevOps代理很可能正在以不同的用户身份运行,并且Az模块尚未为该用户安装。假设代理是作为服务运行的,您可以通过运行 services.msc 并查找 "Azure Pipelines Agent"、"VSTS Agent" 或 "vstsagent.[orgname].[agentname]" [1] 来检查用户。

运行 Get-Module Az -ListAvailable 以查看模块的安装位置。位于 C:\Program Files\PowerShell\Modules 下的模块已为所有用户安装 [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

英文:

The DevOps Agent is most likely running as a different user and the Az modules have not been installed for that user. Assuming the agent is running as a service, you can check the user by running services.msc and look for "Azure Pipelines Agent", "VSTS Agent" or "vstsagent.[orgname].[agentname]" [1].

Run Get-Module Az -ListAvailable to see where the modules have been installed. Modules under C:\Program Files\PowerShell\Modules have been installed for all users [2].

You can install the modules for all users with:

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

huangapple
  • 本文由 发表于 2020年1月6日 23:41:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614950.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定