[英]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
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.