Skip to content

Commit c1df3be

Browse files
authored
Users/suaggar/azure stack m138 (#8103)
* Clear azure rm context in initialize azure (#7778) * Clear azure rm context in initialize azure * resolve PR commets * clear context before azure stack * merge fix * AFC patch update
1 parent be56f17 commit c1df3be

File tree

7 files changed

+20
-13
lines changed

7 files changed

+20
-13
lines changed

Tasks/AzureFileCopyV1/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 1,
1515
"Minor": 0,
16-
"Patch": 139
16+
"Patch": 140
1717

1818
},
1919
"demands": [

Tasks/AzureFileCopyV1/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 1,
1515
"Minor": 0,
16-
"Patch": 139
16+
"Patch": 140
1717
},
1818
"demands": [
1919
"azureps"

Tasks/AzureFileCopyV2/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 2,
1515
"Minor": 0,
16-
"Patch": 7
16+
"Patch": 8
1717

1818
},
1919
"preview": true,

Tasks/AzureFileCopyV2/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 2,
1515
"Minor": 0,
16-
"Patch": 7
16+
"Patch": 8
1717
},
1818
"preview": true,
1919
"demands": [

Tasks/AzurePowerShellV3/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"version": {
1818
"Major": 3,
1919
"Minor": 1,
20-
"Patch": 1
20+
"Patch": 2
2121
},
2222
"releaseNotes": "Added support for Fail on standard error and ErrorActionPreference",
2323
"demands": [

Tasks/AzurePowerShellV3/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"version": {
1818
"Major": 3,
1919
"Minor": 1,
20-
"Patch": 1
20+
"Patch": 2
2121
},
2222
"releaseNotes": "ms-resource:loc.releaseNotes",
2323
"demands": [

Tasks/Common/VstsAzureHelpers_/InitializeFunctions.ps1

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ function Initialize-AzureSubscription {
4242
#Set UserAgent for Azure Calls
4343
Set-UserAgent
4444

45+
# Clear context only for Azure RM
46+
if ($Endpoint.Auth.Scheme -eq 'ServicePrincipal' -and !$script:azureModule -and (Get-Command -Name "Clear-AzureRmContext" -ErrorAction "SilentlyContinue")) {
47+
Write-Host "##[command]Clear-AzureRmContext -Scope Process"
48+
$null = Clear-AzureRmContext -Scope Process
49+
Write-Host "##[command]Clear-AzureRmContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue"
50+
$null = Clear-AzureRmContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
51+
}
52+
4553
$environmentName = "AzureCloud"
4654
if($Endpoint.Data.Environment) {
4755
$environmentName = $Endpoint.Data.Environment
@@ -148,12 +156,6 @@ function Initialize-AzureSubscription {
148156
} else {
149157
# Else, this is AzureRM.
150158
try {
151-
if(Get-Command -Name "Clear-AzureRmContext" -ErrorAction "SilentlyContinue"){
152-
Write-Host "##[command]Clear-AzureRmContext -Scope Process"
153-
$null = Clear-AzureRmContext -Scope Process
154-
Write-Host "##[command]Clear-AzureRmContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue"
155-
$null = Clear-AzureRmContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
156-
}
157159
if (Get-Command -Name "Add-AzureRmAccount" -ErrorAction "SilentlyContinue") {
158160
if (CmdletHasMember -cmdlet "Add-AzureRMAccount" -memberName "EnvironmentName") {
159161
Write-Host "##[command]Add-AzureRMAccount -ServicePrincipal -Tenant $($Endpoint.Auth.Parameters.TenantId) -Credential $psCredential -EnvironmentName $environmentName"
@@ -464,7 +466,12 @@ function Add-AzureStackAzureRmEnvironment {
464466
$armEnv = Get-AzureRmEnvironment -Name $name
465467
if($armEnv -ne $null) {
466468
Write-Verbose "Updating AzureRm environment $name" -Verbose
467-
Remove-AzureRmEnvironment -Name $name -Force | Out-Null
469+
if (CmdletHasMember -cmdlet Remove-AzureRmEnvironment -memberName Force) {
470+
Remove-AzureRmEnvironment -Name $name -Force | Out-Null
471+
}
472+
else {
473+
Remove-AzureRmEnvironment -Name $name | Out-Null
474+
}
468475
}
469476
else {
470477
Write-Verbose "Adding AzureRm environment $name" -Verbose

0 commit comments

Comments
 (0)