在Azure DevOps发布管道中使用Az模块 [英] Using Az module in Azure DevOps Release Pipeline

查看:104
本文介绍了在Azure DevOps发布管道中使用Az模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Azure PowerShell模块(又称Az模块)在Azure DevOps发布管道中.但是,现有的PowerShell选项似乎不起作用.我已经尝试了各种方法,但是安装新的Az模块只会带来很多错误,包括Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook.

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.

常规PowerShell任务没有内置的任何Azure模块.AzurePowerShell任务使用

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

上面的错误很可能是由于Azure PowerShell任务启动时,它在运行我的脚本之前执行以下操作:

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' 

自然,在一个新项目中,我不想使用不再高级的模块来创建PowerShell脚本.

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

再想一想,即使我确实设法克服了这一点,我也必须以某种方式对Azure进行身份验证,而现有的Azure DevOps UI会为我进行身份验证,而我还看不到如何使用Az来做到这一点.模块.

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.

Google搜寻似乎无济于事,因为大多数信息仍与已弃用的AzureRM模块相关.所以...总而言之.

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

如何在Azure DevOps发布管道中使用Azure(Az)Powershell模块?

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

推荐答案

尝试使用Azure Powershell Task版本4.*(预览).此功能仍处于预览状态.与自托管代理一起使用.它将很快发布给Microsoft Hosted代理.

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 .

参考-

这篇关于在Azure DevOps发布管道中使用Az模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆