From 3e043092de8b9a9607a023c35108c32bbfc4a510 Mon Sep 17 00:00:00 2001 From: Sumiran Aggarwal Date: Thu, 19 Jul 2018 14:04:32 +0530 Subject: [PATCH 1/2] Clear azure rm context in initialize azure --- Tasks/AzurePowerShellV3/task.json | 2 +- Tasks/AzurePowerShellV3/task.loc.json | 2 +- Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 | 6 +++++- 3 files changed, 7 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..3a952565e775 100644 --- a/Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 +++ b/Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 @@ -148,7 +148,11 @@ function Initialize-AzureSubscription { } else { # Else, this is AzureRM. try { - if (Get-Command -Name "Add-AzureRmAccount" -ErrorAction "SilentlyContinue") { + if (Get-Command -Name "Add-AzureRmAccount" -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 (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 From fe07e3e2021eb9019381c6e579be66c335ad9191 Mon Sep 17 00:00:00 2001 From: Sumiran Aggarwal Date: Fri, 20 Jul 2018 15:18:39 +0530 Subject: [PATCH 2/2] resolve PR commets --- Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 b/Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 index 3a952565e775..1e6dfe1ca027 100644 --- a/Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 +++ b/Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1 @@ -148,11 +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