I have a build running in Azure DevOps, on an Ubuntu 16.04 hosted build agent. I'm using the latest version of the "Azure Powershell" task (version 4.* preview), which is supposed to be multi-platform, support Powershell core, and support using the Azure Powershell Az module.
However, it doesn't quite work. Before running any of my script, it errors out with:
##[section]Starting: Azure PowerShell script: InlineScript
==============================================================================
Task : Azure PowerShell
Description : Run a PowerShell script within an Azure environment
Version : 4.0.0
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613749)
==============================================================================
##[warning]Can\'t find loc string for key: GeneratingScript
GeneratingScript
[command]/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command . '/home/vsts/work/_temp/e66222aa-283d-4dfd-b5c1-f1d2a4a3ba9f.ps1'
Could not find the module Az.Accounts with given version. If the module was recently installed, retry after restarting the Azure Pipelines task agent.
At /home/vsts/work/_tasks/AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62/4.0.0/InitializeAz.ps1:25 char:5
+ throw ("Could not find the module Az.Accounts with given version. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Could not find ...nes task agent.:String) [], RuntimeException
+ FullyQualifiedErrorId : Could not find the module Az.Accounts with given version. If the module was recently installed, retry after restarting the Azure Pipelines task agent.
##[error]PowerShell exited with code '1'.
##[error]PowerShell wrote one or more lines to the standard error stream.
##[section]Finishing: Azure PowerShell script: InlineScript
The Az Powershell module appears to work/load correctly on the Windows VS2017 hosted agent, but no luck on Ubuntu. Any recommendations on fixing this?
I was able to get Az Powershell working in my Azure DevOps build on an Ubuntu agent by adding a prior build step that installs the Az Powershell module on the build agent.
I added a powershell script to install the Az module and uninstall the Azure-Rm module; and I called it from a command-line task so I could wrap it in
sudo
to make it a global change.Here's the command-line task (YAML):
And here's the
build/install-az-modules.ps1
script: