如何在VSTS任务中使用最新的AzureRM

时间:2017-08-24 10:13:31

标签: powershell azure azure-devops

我想执行一个命令来删除远程azure资源组上的主题或队列。其中一个命令是Get-AzureRmServiceBusQueue'。

我在VSTS的托管代理中使用Azure Powershell任务(使用Azure资源管理器)。此任务使用Azure Powershell 2.0.1。

当我执行释放时,代理会返回此失败:

"[error]The term 'Get-AzureRmServiceBusQueue' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."

我检查过ServiceBus cmdlet仅在较新版本的Azure Powershell中提供(例如:最新的4.3.1)。

我可以执行一个'安装模块 - 名称AzureRM' ?

2 个答案:

答案 0 :(得分:2)

根据你的描述,我在我的实验室进行测试。目前,如果您使用最新版本的Azure PowerShell,则VSTS任务使用4.2.1版本。 cmdlet Get-AzureRmServiceBusQueue适用于我的任务。

enter image description here

代理队列我使用Hosted VS2017。这是我得到的日志。

2017-08-25T02:34:00.0731521Z ##[section]Starting: Azure PowerShell script: InlineScript
2017-08-25T02:34:00.0911526Z ==============================================================================
2017-08-25T02:34:00.0921520Z Task         : Azure PowerShell
2017-08-25T02:34:00.0921520Z Description  : Run a PowerShell script within an Azure environment
2017-08-25T02:34:00.0921520Z Version      : 2.0.1
2017-08-25T02:34:00.0921520Z Author       : Microsoft Corporation
2017-08-25T02:34:00.0921520Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613749)
2017-08-25T02:34:00.0921520Z ==============================================================================
2017-08-25T02:34:02.8332045Z ##[command]Import-Module -Name C:\Modules\azurerm_4.2.1\AzureRM\4.2.1\AzureRM.psd1 -Global
2017-08-25T02:34:11.8296290Z ##[command]Import-Module -Name C:\Modules\azure_4.2.1\AzureRM.Profile\3.2.1\AzureRM.Profile.psm1 -Global
2017-08-25T02:34:15.2798961Z ##[command]Add-AzureRMAccount -ServicePrincipal -Tenant ******** -Credential System.Management.Automation.PSCredential -Environment AzureCloud
2017-08-25T02:34:16.1729615Z ##[command]Select-AzureRMSubscription -SubscriptionId 3b4d41fa-****-****-bc11-13d221b3b77d -TenantId ********
2017-08-25T02:34:16.3229723Z ##[command]& 'd:\a\_temp\a063a14b-863f-4439-bd37-29f7ee515754.ps1' 
2017-08-25T02:34:16.9640151Z 
2017-08-25T02:34:16.9640151Z 
2017-08-25T02:34:16.9640151Z     Directory: C:\Modules\azure_4.2.1
2017-08-25T02:34:16.9640151Z 
2017-08-25T02:34:16.9640151Z 
2017-08-25T02:34:16.9640151Z ModuleType Version    Name                                ExportedCommands                                             
2017-08-25T02:34:16.9640151Z ---------- -------    ----                                ----------------                                             
2017-08-25T02:34:16.9640151Z Script     4.2.1      Azure                               {Get-AzureAutomationCertificate, Get-AzureAutomationConnec...
2017-08-25T02:34:16.9650152Z 
2017-08-25T02:34:16.9650152Z 
2017-08-25T02:34:16.9650152Z     Directory: C:\Program Files\WindowsPowerShell\Modules

另外,您可以参考此link:Hosted agents

  

托管:AzureRM PowerShell 3.6.0

     

托管VS2017:AzureRM PowerShell 4.1.0(根据我的测试,目前版本是4.2.1)。

答案 1 :(得分:1)

您需要使用 Hosted 2017构建代理

2.0.1 版本是 Azure PowerShell任务版本而不是PowerShell版本,您可以使用以下代码检查PowerShell版本:--env.includeCss

相关问题