在托管2017代理(VSTS-Visual Studio Team Services)上升级AzureRM Powershell [英] Upgrade AzureRM Powershell on Hosted 2017 Agent (VSTS - Visual Studio Team Services)
问题描述
我正在通过Visual Studio Teams Services(在线)使用版本管理.我们使用托管构建代理,我真的想避免管理自定义代理的开销.
I am using release management through Visual Studio Teams Services (online). We use Hosted build Agents and I really want to avoid the overhead of managing custom agents.
我需要的一项是AzureRM PowerShell模块.低于5.1.1的版本是在代理上可用,但我需要6.0.0.
One item I do need is the AzureRM PowerShell module. Versions up to 5.1.1 are available on the agent but I need 6.0.0.
我想做的是在发行过程(PowerShell)中使用一个步骤来获取6.0.0版并改用thart,但是我无法完全使其正常工作.我已经尝试了几种尚未全部解决的方法,当前的方法是:
What I would like to do is use a step in my release process (PowerShell) to aquire version 6.0.0 and use thart instead, however I cant quite get it to work. I have tried a few approaches that have all come unstuck, the current one is:
Write-Output "------------------ Install package provider ------------------"
Find-PackageProvider -Name "NuGet" | Install-PackageProvider -Scope CurrentUser -Force
Write-Output "------------------ Remove Modules ------------------"
Get-Module -ListAvailable | Where-Object {$_.Name -like 'AzureRM*'} | Remove-Module
Write-Output "------------------ Install the AzureRM version we want - 6.0.1! ------------------"
Install-Package AzureRM -RequiredVersion 6.0.1 -Scope CurrentUser -Force
Write-Output "------------------ Import AzureRM 6.0.1 ------------------"
Import-Module AzureRM -RequiredVersion 6.0.1
这一切都正常(即不会崩溃...),但是当我尝试使用6.0.1 cmdlet之一时,出现错误.
This all works fine (i.e. does not crash...) but then when I try and use one of the 6.0.1 cmdlets I get an error.
Get-AzureRmADGroup:尚未执行Azure PowerShell会话 正确初始化.请导入模块,然后重试.
Get-AzureRmADGroup : The Azure PowerShell session has not been properly initialized. Please import the module and try again.
有什么想法可以解决我的问题或可以用来部署AzureRM 6.0.1并将其用于托管代理的替代策略吗?
Any idea of where I am going wrong or alternate strategies I can use to deploy AzureRM 6.0.1 and use it on a hosted agent?
推荐答案
我终于弄清楚了-为遭受同样痛苦的其他人添加答案.
I finally figured it out - adding an answer for anyone else that suffers the same.
关键是在升级AzureRM模块后登录.
The key is to login after the AzureRM module is upgraded.
PowerShell代码:
Write-Output "------------------ Start: Upgrade AzureRM on build host ------------------"
Write-Output "- - - - - Install package provider"
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
Write-Output "- - - - - List Modules Before"
Get-Module -ListAvailable| where {$_.Name -Like "*AzureRM*"} | Select Name, Version
Write-Output "- - - - - Remove alll existing AzureRM Modules"
Get-Module -ListAvailable | Where-Object {$_.Name -like '*AzureRM*'} | Remove-Module -Force
Write-Output "- - - - - Install AzureRM 6.0.1"
Install-Module -Name AzureRM -RequiredVersion 6.0.1 -Force -Scope CurrentUser
Write-Output "- - - - - Import AzureRM 6.0.1"
Import-Module AzureRM -Force -Verbose -Scope Local
Write-Output "- - - - - List Modules After"
Get-Module -ListAvailable| where {$_.Name -Like "*AzureRM*"} | Select Name, Version
Write-Output "------------------ End: Upgrade AzureRM on build host ------------------"
Write-Output "------------------ Start: LoginToAzure ------------------"
$SecurePassword = ConvertTo-SecureString $AdminPassword -AsPlainText -Force
$AdminCredential = New-Object System.Management.Automation.PSCredential ($AdminUserEmailAddress, $SecurePassword)
Login-AzureRmAccount -Credential $AdminCredential
Get-AzureRmSubscription –SubscriptionId $SubscriptionId | Select-AzureRmSubscription
Write-Output "------------------ End: LoginToAzure ------------------"
这篇关于在托管2017代理(VSTS-Visual Studio Team Services)上升级AzureRM Powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!