Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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?

like image 904
kagarlickij Avatar asked Jan 10 '20 12:01

kagarlickij


1 Answers

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

like image 178
bunzab Avatar answered Oct 15 '22 01:10

bunzab