Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Az module in Azure DevOps Release Pipeline

I want to use the Azure PowerShell Module (aka Az Module) in an Azure DevOps Release Pipeline. However, the existing PowerShell options don't seem to work. I've tried various things, but installing the new Az module just brings up a ton of errors, including Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook.

The regular PowerShell task doesn't have any azure modules built in. And the Azure PowerShell task uses the Azure RM PowerShell module, which has been retired (i.e. it is still supported, but no new features will be added).

The error, above, is most likely caused because when the Azure PowerShell task start, it performs the following before running my script:

2019-01-13T13:34:14.5416432Z ==============================================================================
2019-01-13T13:34:14.5416555Z Task         : Azure PowerShell
2019-01-13T13:34:14.5416623Z Description  : Run a PowerShell script within an Azure environment
2019-01-13T13:34:14.5416705Z Version      : 3.1.18
2019-01-13T13:34:14.5416762Z Author       : Microsoft Corporation
2019-01-13T13:34:14.5416831Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613749)
2019-01-13T13:34:14.5416969Z ==============================================================================
2019-01-13T13:34:20.3546127Z ##[command]Import-Module -Name C:\Modules\AzureRm_6.7.0\AzureRM\6.7.0\AzureRM.psd1 -Global
2019-01-13T13:34:58.4365259Z ##[command]Clear-AzureRmContext -Scope Process
2019-01-13T13:34:59.2732327Z ##[command]Disable-AzureRmContextAutosave -ErrorAction SilentlyContinue
2019-01-13T13:35:00.1691359Z ##[command]Add-AzureRMAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2019-01-13T13:35:01.5702545Z ##[command] Select-AzureRMSubscription -SubscriptionId d5eaaba3-2968-456a-98a4-e53e961fc896 -TenantId ***
2019-01-13T13:35:02.1592660Z ##[command]& 'D:\a\r1\a\ws-build\tools\install-dependencies.ps1' 

Naturally, on a new project I don't want to be creating PowerShell scripts with a module that will no longer be advanced.

And thinking ahead, even if I do manage to get past this, I will have to authenticate somehow with Azure, which the existing Azure DevOps UI does for me, and I can't yet see how to do that with the Az Module. Add a subscription into the Azure context

Googling doesn't seem to help, as most information still relates the deprecated AzureRM module. So... In summary.

How do I use the Azure (Az) Powershell module in an Azure DevOps release pipeline?

like image 741
Colin Mackay Avatar asked Jan 13 '19 14:01

Colin Mackay


1 Answers

Try using Azure Powershell Task version 4.* (Preview). This feature is still in preview. Use this with Self Hosted agents. This will be released for Microsoft Hosted agent soon .

Reference - https://developercommunity.visualstudio.com/content/problem/434058/unable-to-use-new-az-module-in-azure-devops.html

enter image description here

like image 198
Divyanshu mehta Avatar answered Oct 04 '22 18:10

Divyanshu mehta