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 sup
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):
steps:
- displayName: 'Install Az Powershell Modules'
script: |
sudo /usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -File "$(Build.Repository.LocalPath)/build/install-az-modules.ps1"
And here's the build/install-az-modules.ps1
script:
<#
.SYNOPSIS
Build agent script to install Az Powershell modules. This script should be run as sudo.
On a linux build agent, this command can be run as:
sudo /usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '$(Build.Repository.LocalPath)/build/install-az-modules.ps1'
#>
# Disable status info to clean up build agent stdout
$global:ProgressPreference = 'SilentlyContinue'
$global:VerbosePreference = "SilentlyContinue"
$azureRmModule = Get-InstalledModule AzureRM -ErrorAction SilentlyContinue
if ($azureRmModule) {
Write-Host 'AzureRM module exists. Removing it'
Uninstall-Module -Name AzureRM -AllVersions
Write-Host 'AzureRM module removed'
}
Write-Host 'Installing Az module...'
Install-Module Az -Force -AllowClobber
if (Get-Command Uninstall-AzureRm -ErrorAction SilentlyContinue) {
Write-Host 'Running Uninstall-AzureRm...'
Uninstall-AzureRm
}