From 88cb0976594582d757056de9f5c89887fe45c3fe Mon Sep 17 00:00:00 2001 From: Sumiran Aggarwal Date: Mon, 23 Jul 2018 11:31:16 +0530 Subject: [PATCH] Clear azure rm context in initialize azure (#7778) * Clear azure rm context in initialize azure * resolve PR commets --- Tasks/AzurePowerShellV3/task.json | 2 +- Tasks/AzurePowerShellV3/task.loc.json | 2 +- Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Tasks/AzurePowerShellV3/task.json b/Tasks/AzurePowerShellV3/task.json index 6d9db94944f9..4872e4f5a3e7 100644 --- a/Tasks/AzurePowerShellV3/task.json +++ b/Tasks/AzurePowerShellV3/task.json @@ -17,7 +17,7 @@ "version": { "Major": 3, "Minor": 1, - "Patch": 0 + "Patch": 1 }, "releaseNotes": "Added support for Fail on standard error and ErrorActionPreference", "demands": [ diff --git a/Tasks/AzurePowerShellV3/task.loc.json b/Tasks/AzurePowerShellV3/task.loc.json index 71e2543ac502..e212cb2eb692 100644 --- a/Tasks/AzurePowerShellV3/task.loc.json +++ b/Tasks/AzurePowerShellV3/task.loc.json @@ -17,7 +17,7 @@ "version": { "Major": 3, "Minor": 1, - "Patch": 0 + "Patch": 1 }, "releaseNotes": "ms-resource:loc.releaseNotes", "demands": [ diff --git a/Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 b/Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 index 17d5714424c2..1e6dfe1ca027 100644 --- a/Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 +++ b/Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 @@ -148,7 +148,13 @@ function Initialize-AzureSubscription { } else { # Else, this is AzureRM. try { - if (Get-Command -Name "Add-AzureRmAccount" -ErrorAction "SilentlyContinue") { + if(Get-Command -Name "Clear-AzureRmContext" -ErrorAction "SilentlyContinue"){ + Write-Host "##[command]Clear-AzureRmContext -Scope Process" + $null = Clear-AzureRmContext -Scope Process + Write-Host "##[command]Clear-AzureRmContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue" + $null = Clear-AzureRmContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue + } + if (Get-Command -Name "Add-AzureRmAccount" -ErrorAction "SilentlyContinue") { if (CmdletHasMember -cmdlet "Add-AzureRMAccount" -memberName "EnvironmentName") { Write-Host "##[command]Add-AzureRMAccount -ServicePrincipal -Tenant $($Endpoint.Auth.Parameters.TenantId) -Credential $psCredential -EnvironmentName $environmentName" $null = Add-AzureRMAccount -ServicePrincipal -Tenant $Endpoint.Auth.Parameters.TenantId -Credential $psCredential -EnvironmentName $environmentName