简体   繁体   English

Azure DevOps PowerShell 任务无法加载“Az.CosmosDB”模块

[英]Azure DevOps PowerShell task fails to load 'Az.CosmosDB' module

I have an Azure DevOps pipeline to rotate Cosmos DB account keys.我有一个 Azure DevOps 管道来轮换 Cosmos DB 帐户密钥。 To do this, I'm using PowerShell and the New-AzCosmosDBAccountKey cmdlet.为此,我使用了 PowerShell 和New-AzCosmosDBAccountKey cmdlet。

For some unknown reason, the Az.CosmosDB module is not installed with Az , so it needs to be installed manually each time the pipeline is run.由于某种未知的原因, Az.CosmosDB模块没有随Az一起安装,因此每次运行管道时都需要手动安装。

Install-Module -Name Az.CosmosDb -AllowClobber -Force

When I run this locally everything works as expected, but within Azure DevOps I see an error当我在本地运行它时,一切都按预期工作,但在 Azure DevOps 中我看到一个错误

The 'Get-AzCosmosDBAccountKey' command was found in the module 'Az.CosmosDB', but the module could not be loaded.在模块“Az.CosmosDB”中找到了“Get-AzCosmosDBAccountKey”命令,但无法加载该模块。

What might be happening in Azure DevOps that differs from what is happening locally? Azure DevOps 中可能发生的事情与本地发生的事情不同?

The answer here is that an update was made to the Az.CosmosDb module so that it specifically requires version 1.9.4 (or higher) of Az.Accounts .这里的答案是对Az.CosmosDb模块进行了更新,因此它特别需要Az.Accounts 1.9.4(或更高版本) Az.Accounts However, on the Azure DevOps hosted agent they use version 1.9.3.但是,在 Azure DevOps 托管代理上,他们使用版本 1.9.3。

To fix, I changed the command that manually installs the Az.CosmosDb module -为了修复,我更改了手动安装Az.CosmosDb模块的命令 -

Install-Module -Name Az.CosmosDb -RequiredVersion 0.1.6 -AllowClobber -Force

Note笔记

When I found on the PowerShell Gallery that all versions of the Az.CosmosDb module were < 1.0.0 I did some investigation and it turns out that the module is still in preview, despite Cosmos DB having existed for years.当我在 PowerShell Gallery 上发现Az.CosmosDb模块的所有版本都小于1.0.0 时,我做了一些调查,结果发现该模块仍处于预览状态,尽管 Cosmos DB 已经存在多年。 This explains why the module is not installed along side all other Az.* modules when installing Az .这解释了为什么在安装Az时该模块没有与所有其他Az.*模块一起安装。

What is very frustrating is that there is no mention anywhere on the documentation for the module that it is in preview.非常令人沮丧的是,该模块的文档中没有任何地方提到它处于预览状态。 If there were, it would probably have saved me a good chunk of time!如果有的话,它可能会为我节省大量时间!

Please check when you run DevOps Pipeline, which agent pool you are using.请检查您在运行 DevOps Pipeline 时使用的代理池。 If you use microsoft-hosted agent, each time you run a pipeline, you get a fresh virtual machine.如果您使用 Microsoft 托管的代理,则每次运行管道时,您都会获得一个全新的虚拟机。 The virtual machine is discarded after one use.虚拟机在使用一次后被丢弃。 So you need to install the Az.CosmosDB module manually each time.所以每次都需要手动安装Az.CosmosDB模块。

You could also deploy an agent on your local machine, in this way, it's supposed not need to nstall the Az.CosmosDB module manually each time.您也可以在本地机器上部署一个代理,这样就不需要每次都手动安装Az.CosmosDB模块。

https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser

Seems today Azure DevOps finally broke everything, old variant with似乎今天 Azure DevOps 终于打破了一切,旧的变体

Install-Module Az.CosmosDB -RequiredVersion 0.1.6 -Force

has stopped working.已停止工作。 Amazing, the whole experience with Az DevOps and Azure technologies are pretty the same, each time they just suddenly have stopped working at random places!令人惊奇的是,使用 Az DevOps 和 Azure 技术的整个体验几乎相同,每次它们只是突然在随机位置停止工作!

UPD: The gallery source address is dead https://www.powershellgallery.com/packages/Az.CosmosDB/0.1.6 , looks that is the reason UPD:画廊源地址已死https://www.powershellgallery.com/packages/Az.CosmosDB/0.1.6 ,看起来是这个原因

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将变量值从 AZ Powershell 任务中的一个 Powershell 脚本传递到 Azure DevOps Release Pipeline 中下一个 AZ Powershell 任务中的另一个脚本 - Pass variable value from one Powershell script in AZ Powershell task to another script in the next AZ Powershell task in Azure DevOps Release Pipeline Azure DevOps 任务内联脚本与 powershell 不会因错误而导致任务失败 - Azure DevOps task inline script with powershell does not fails the task on error macOS 上的 Azure Az PowerShell 模块 - Azure Az PowerShell module on macOS 在 Azure DevOps 管道中,在执行 az login 时使用 powershell 任务中的变量会导致 ArgumentParseError - In Azure DevOps pipelines, using variables in the powershell task results in ArgumentParseError when doing az login 如何检测 Azure DevOps 代理上安装了哪个版本的 Az PowerShell 模块集合? - How to detect which version of the Az PowerShell module collection is installed on an Azure DevOps agent? 从 Azure DevOps powershell 任务调用 sqlcmd 失败 - Calling sqlcmd from Azure DevOps powershell task Fails 从 Azure DevOps 管道加载 Az.Kusto 2.0.0 PowerShell 模块时出现问题 - Problem loading Az.Kusto 2.0.0 PowerShell Module from Azure DevOps Pipeline Azure DevOps(VSTS)-在托管代理上使用Azure Az PowerShell - Azure DevOps (VSTS) - using Azure Az PowerShell on a Hosted Agent 无法在 linux 上安装 Azure Az PowerShell 模块 - Cannot install the Azure Az PowerShell module on linux Azure devops powershell 任务问题 - Azure devops powershell task issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM