Skip to content

Commit

Permalink
Clear azure rm context in initialize azure (#7778)
Browse files Browse the repository at this point in the history
* Clear azure rm context in initialize azure

* resolve PR commets
  • Loading branch information
SumiranAgg authored and suaggar committed Jul 25, 2018
1 parent eb5df15 commit 88cb097
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 3,
"Minor": 1,
"Patch": 0
"Patch": 1
},
"releaseNotes": "Added support for Fail on standard error and ErrorActionPreference",
"demands": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 3,
"Minor": 1,
"Patch": 0
"Patch": 1
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"demands": [
Expand Down
8 changes: 7 additions & 1 deletion Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 88cb097

Please sign in to comment.