【发布时间】:2020-09-18 17:17:58
【问题描述】:
我想在 Azure DevOps 发布管道中使用 Azure PowerShell Module(又名 Az 模块)。但是,现有的 PowerShell 选项似乎不起作用。我尝试了各种方法,但安装新的 Az 模块只会带来大量错误,包括 Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook.
常规 PowerShell 任务没有内置任何 azure 模块。Azure PowerShell 任务使用 Azure RM PowerShell module,它已被淘汰(即它仍然受支持,但不会添加新功能)。
上面的错误很可能是因为当 Azure PowerShell 任务启动时,它在运行我的脚本之前执行了以下操作:
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 脚本。
提前想一想,即使我确实设法克服了这个问题,我也必须以某种方式使用 Azure 进行身份验证,现有的 Azure DevOps UI 为我做的,我还看不出如何使用 Az模块。
谷歌搜索似乎没有帮助,因为大多数信息仍然与已弃用的 AzureRM 模块有关。所以...总结一下。
如何在 Azure DevOps 发布管道中使用 Azure (Az) Powershell 模块?
【问题讨论】:
-
这即将推出。根据此 GitHub 评论,Az 模块将于 2019 年 2 月推出:github.com/Microsoft/azure-pipelines-tasks/issues/…
-
我尝试在 Azure devops 中使用 Az 模块。在这里写了一个简短的介绍 - medium.com/@harioverhere/…
标签: azure-devops azure-pipelines azure-powershell