在 Hosted 2017 Agent 上升级 AzureRM Powershell (VSTS - Visual Studio Team Services) [英] Upgrade AzureRM Powershell on Hosted 2017 Agent (VSTS - Visual Studio Team Services)

查看:19
本文介绍了在 Hosted 2017 Agent 上升级 AzureRM Powershell (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 ------------------"

这篇关于在 Hosted 2017 Agent 上升级 AzureRM Powershell (VSTS - Visual Studio Team Services)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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