“Could not find the module Az.Accounts with given version” error when running Azure DevOps job in Docker

江枫思渺然 提交于 2020-05-29 08:23:46

问题


I install PowerShell and Az module in container based on ubuntu:16.04

RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    wget https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb && \
    dpkg -i packages-microsoft-prod.deb && \
    apt-get update -y && \
    apt-get install powershell -y && \
    pwsh -c "Install-Module -Name Az -Force"

It works fine when I ssh to Docker running on my machine,
..but fails with error "Could not find the module Az.Accounts with given version" when executed in Azure DevOps pipeline:

Any ideas how to fix?


回答1:


What version of Az.Accounts is being loaded? If it is 2.0.0-preview the DevOps task will fail.

You can check for it using Get-InstalledModule Az.Accounts -AllVersions

If it is the case use:

Uninstall-Module -Name Az.Accounts -RequiredVersion 2.0.0-preview -AllowPrerelease

to remove the preview then add the current version:

Install-Module -Name Az.Accounts -RequiredVersion 1.7.0

I have no idea why the preview gets installed but it has plagued me for a while...




回答2:


The document Install the Azure PowerShell module warns below:

You can't have both the AzureRM and Az modules installed for PowerShell 5.1 for Windows at the same time. If you need to keep AzureRM available on your system, install the Az module for PowerShell Core 6.x or later. To do this, install PowerShell Core 6.x or later and then follow these instructions in a PowerShell Core terminal.

It will cause problem if AzureRM an Az Modules are both installed.

You can have a try to use azure powershell v4 or v3 task as discussed in this thread.

You can also have a try to run below script to uninstall AzureRM. For details please check out the detailed scripts in this solution

Uninstall-Module -Name AzureRM -AllVersions



来源:https://stackoverflow.com/questions/59681516/could-not-find-the-module-az-accounts-with-given-version-error-when-running-az

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!