kagarlickij
kagarlickij

Reputation: 8107

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

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: enter image description here

Any ideas how to fix?

Upvotes: 13

Views: 30907

Answers (2)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30313

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

Upvotes: 0

bunzab
bunzab

Reputation: 389

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

Upvotes: 5

Related Questions