Skip to content

Commit 9a6182a

Browse files
author
Ajay Kumar Yadav
authored
Diagnostics cmdlet switch fix (#3067)
1 parent 6822d9b commit 9a6182a

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

Tasks/AzureCloudPowerShellDeployment/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
"loc.messages.Nofileswerefoundtodeploywithsearchpattern0": "No files were found to deploy with search pattern {0}",
3636
"loc.messages.Foundmorethanonefiletodeploywithsearchpattern0Therecanbeonlyone": "Found more than one file to deploy with search pattern {0}. There can be only one.",
3737
"loc.messages.Storagekeysaredefinedininvalidformat": "Storage keys are defined in invalid format.",
38-
"loc.messages.Unabletofind0usingprovidedsubscription": "Unable to find {0} using provided subscription"
38+
"loc.messages.Unabletofind0usingprovidedsubscription": "Unable to find {0} using provided subscription",
39+
"loc.messages.Currentversionofazurepowershelldontsupportexternalstorageaccountforconfiguringdiagnostics": "Current version of azure powershell don't support external storage account for configuring diagnostics."
3940
}

Tasks/AzureCloudPowerShellDeployment/Utility.ps1

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,25 @@ function Get-DiagnosticsExtensions($storageAccount, $extensionsPath, $storageAcc
140140
$storageAccountKey = $primaryStorageKey
141141
}
142142

143-
Write-Host "New-AzureServiceDiagnosticsExtensionConfig -Role $role -StorageAccountName $storageAccountName -StorageAccountKey <storageKey> -DiagnosticsConfigurationPath $fullExtPath"
144-
$wadconfig = New-AzureServiceDiagnosticsExtensionConfig -Role $role -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey -DiagnosticsConfigurationPath $fullExtPath
143+
if((CmdletHasMember "StorageAccountName") -and (CmdletHasMember "StorageAccountKey"))
144+
{
145+
Write-Host "New-AzureServiceDiagnosticsExtensionConfig -Role $role -StorageAccountName $storageAccountName -StorageAccountKey <storageKey> -DiagnosticsConfigurationPath $fullExtPath"
146+
$wadconfig = New-AzureServiceDiagnosticsExtensionConfig -Role $role -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey -DiagnosticsConfigurationPath $fullExtPath
147+
}
148+
else
149+
{
150+
try
151+
{
152+
$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
153+
Write-Host "New-AzureServiceDiagnosticsExtensionConfig -Role $role -StorageContext $StorageContext -DiagnosticsConfigurationPath $fullExtPath"
154+
$wadconfig = New-AzureServiceDiagnosticsExtensionConfig -Role $role -StorageContext $StorageContext -DiagnosticsConfigurationPath $fullExtPath
155+
}
156+
catch
157+
{
158+
Write-Warning (Get-VstsLocString -Key "Currentversionofazurepowershelldontsupportexternalstorageaccountforconfiguringdiagnostics")
159+
throw $_.Exception
160+
}
161+
}
145162

146163
#Add each extension configuration to the array for use by caller
147164
$diagnosticsConfigurations += $wadconfig
@@ -177,4 +194,15 @@ function Parse-StorageKeys($storageAccountKeys)
177194
}
178195
}
179196
return $roleStorageKeyMap
197+
}
198+
199+
function CmdletHasMember($memberName) {
200+
try{
201+
$cmdletParameter = (gcm New-AzureServiceDiagnosticsExtensionConfig).Parameters.Keys.Contains($memberName)
202+
return $cmdletParameter
203+
}
204+
catch
205+
{
206+
return false;
207+
}
180208
}

Tasks/AzureCloudPowerShellDeployment/task.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 1,
1515
"Minor": 0,
16-
"Patch": 32
16+
"Patch": 33
1717
},
1818
"demands": [
1919
"azureps"
@@ -186,6 +186,7 @@
186186
"Nofileswerefoundtodeploywithsearchpattern0": "No files were found to deploy with search pattern {0}",
187187
"Foundmorethanonefiletodeploywithsearchpattern0Therecanbeonlyone": "Found more than one file to deploy with search pattern {0}. There can be only one.",
188188
"Storagekeysaredefinedininvalidformat": "Storage keys are defined in invalid format.",
189-
"Unabletofind0usingprovidedsubscription" :"Unable to find {0} using provided subscription"
189+
"Unabletofind0usingprovidedsubscription" :"Unable to find {0} using provided subscription",
190+
"Currentversionofazurepowershelldontsupportexternalstorageaccountforconfiguringdiagnostics": "Current version of azure powershell don't support external storage account for configuring diagnostics."
190191
}
191192
}

Tasks/AzureCloudPowerShellDeployment/task.loc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 1,
1515
"Minor": 0,
16-
"Patch": 32
16+
"Patch": 33
1717
},
1818
"demands": [
1919
"azureps"
@@ -186,6 +186,7 @@
186186
"Nofileswerefoundtodeploywithsearchpattern0": "ms-resource:loc.messages.Nofileswerefoundtodeploywithsearchpattern0",
187187
"Foundmorethanonefiletodeploywithsearchpattern0Therecanbeonlyone": "ms-resource:loc.messages.Foundmorethanonefiletodeploywithsearchpattern0Therecanbeonlyone",
188188
"Storagekeysaredefinedininvalidformat": "ms-resource:loc.messages.Storagekeysaredefinedininvalidformat",
189-
"Unabletofind0usingprovidedsubscription": "ms-resource:loc.messages.Unabletofind0usingprovidedsubscription"
189+
"Unabletofind0usingprovidedsubscription": "ms-resource:loc.messages.Unabletofind0usingprovidedsubscription",
190+
"Currentversionofazurepowershelldontsupportexternalstorageaccountforconfiguringdiagnostics": "ms-resource:loc.messages.Currentversionofazurepowershelldontsupportexternalstorageaccountforconfiguringdiagnostics"
190191
}
191192
}

0 commit comments

Comments
 (0)