【问题标题】:How to use latest AzureRM in a VSTS task如何在 VSTS 任务中使用最新的 AzureRM
【发布时间】:2017-08-24 10:13:31
【问题描述】:

我想执行命令以删除远程 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)。

我可以执行“Install-Module -Name AzureRM”吗?

【问题讨论】:

  • 我没有使用过 VSTS,也没有用于测试的帐户,但是,如果它运行的是 PowerShell 版本 5 或更高版本,您应该能够运行如图所示的安装 cmdlet。您还可以将其与 -RequiredVersion 参数结合使用,以确保您为每个构建获得一致的版本。

标签: powershell azure azure-devops


【解决方案1】:

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

代理队列我使用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)。

【讨论】:

  • @Patrick Peters 使用托管的 2017 年 bulid 代理对您有用吗?
【解决方案2】:

您需要使用Hosted 2017 build agent

2.0.1版本是Azure PowerShell Task版本而不是PowerShell版本,您可以使用此代码查看PowerShell版本:Write-Output $PSVersionTable.PSVersion

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    相关资源
    最近更新 更多