英文:
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
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论