diff --git a/Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 b/Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 index 26c2e19cbce6..c4ed66ee733c 100644 --- a/Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 +++ b/Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 @@ -53,6 +53,55 @@ param ( [String]$psOnRemoteScriptBlockString = "Invoke-PsOnRemote -MachineDnsName $fqdn -ScriptPath `$scriptPath -WinRMPort $port -Credential `$credential -ScriptArguments `$scriptArguments -InitializationScriptPath `$initializationScriptPath -SessionVariables `$parsedSessionVariables $skipCACheckOption $httpProtocolOption $enableDetailedLoggingOption" [scriptblock]$psOnRemoteScriptBlock = [scriptblock]::Create($psOnRemoteScriptBlockString) $deploymentResponse = Invoke-Command -ScriptBlock $psOnRemoteScriptBlock - + + # Telemetry data logic through ps session + try{ + if($skipCACheckOption) + { + $sessionOption = New-PSSessionOption -SkipCACheck + } + else + { + $sessionOption = New-PSSessionOption + } + $secpasswd = ConvertTo-SecureString $credential.Password -AsPlainText -Force + $psCredential = New-Object System.Management.Automation.PSCredential($credential.UserName, $secpasswd) + if($httpProtocolOption -eq '-UseHttp') + { + $session = New-PSSession -Computer $fqdn -Port $port -Credential $psCredential -SessionOption ($sessionOption ) + } + else + { + $session = New-PSSession -Computer $fqdn -Port $port -Credential $psCredential -SessionOption ($sessionOption ) -UseSSL + } + $VmUuidHash = Invoke-Command -Session $session -ScriptBlock { + $sha = New-Object System.Security.Cryptography.SHA512CryptoServiceProvider + $computerDetails = Get-WmiObject -class Win32_ComputerSystemProduct -namespace root\CIMV2 + $encoding = [system.Text.Encoding]::ASCII + $uuidHash = [System.BitConverter]::ToString( $sha.ComputeHash($encoding.GetBytes($computerDetails.UUID))) + $uuidHash = $uuidHash -replace "-" , "" + return $uuidHash + } + $isAzureVm = Invoke-Command -Session $session -ScriptBlock { + (Get-Process -Name 'WindowsAzureGuestAgent' -ErrorAction Ignore) | Select-Object -First 1 | ForEach-Object { + if($_.Path) + { + return $true + } + else + { + return $false + } + } + } + $deploymentResponse | Add-Member "IsAzureVm" $IsAzureVm -Force + $deploymentResponse | Add-Member "VmUuidHash" $VmUuidHash -Force + } + catch + { + Write-Verbose "Error during fetching telemetry = $_" + $deploymentResponse | Add-Member "TelemetryError" $_ -Force + } + Write-Output $deploymentResponse } diff --git a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 index fcad9063f49b..c47976b38605 100644 --- a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 +++ b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 @@ -54,6 +54,7 @@ $ErrorActionPreference = 'Stop' $deploymentOperation = 'Deployment' $envOperationStatus = "Passed" +$jobId = $env:SYSTEM_JOBID; # enabling detailed logging only when system.debug is true $enableDetailedLoggingString = $env:system_debug @@ -65,6 +66,36 @@ if ($enableDetailedLoggingString -ne "true") # Telemetry Import-Module $PSScriptRoot\ps_modules\TelemetryHelper +function Publish-AzureTelemetry + { + param([object] $deploymentResponse, + [string] $jobId ) + if($deploymentResponse){ + $jsonString = -join("{") + if([bool]($deploymentResponse.PSobject.Properties.name -match "IsAzureVm")){ + $jsonString = -join( $jsonString, + "`"IsAzureVm`" : `"$($deploymentResponse.IsAzureVm)`"" , + ",") + } + if([bool]($deploymentResponse.PSobject.Properties.name -match "VmUuidHash")){ + $jsonString = -join( $jsonString, + "`"VmUuidHash`" : `"$($deploymentResponse.VmUuidHash)`"", + ",") + } + if([bool]($deploymentResponse.PSobject.Properties.name -match "TelemetryError")){ + $jsonString = -join( $jsonString, + "`"TelemetryError`" : `"$($deploymentResponse.TelemetryError)`"", + ",") + } + + $jsonString = -join( $jsonString, + "`"JobId`" : `"$jobId`"" , "}") + } + + $telemetryString ="##vso[telemetry.publish area=TaskHub;feature=PowerShellOnTargetMachines]$jsonString" + Write-Host $telemetryString + } + try { $connection = Get-VssConnection -TaskContext $distributedTaskContext @@ -105,10 +136,10 @@ if($runPowershellInParallel -eq "false" -or ( $resources.Count -eq 1 ) ) $status = $deploymentResponse.Status Write-Output (Get-LocalizedString -Key "Deployment status for machine '{0}' : '{1}'" -ArgumentList $displayName, $status) + Publish-AzureTelemetry -deploymentResponse $deploymentResponse -jobId $jobId if ($status -ne "Passed") { - Write-Telemetry "DTLSDK_Error" $deploymentResponse.DeploymentSummary Write-Verbose $deploymentResponse.Error.ToString() $errorMessage = $deploymentResponse.Error.Message throw $errorMessage @@ -145,6 +176,8 @@ else Write-ResponseLogs -operationName $deploymentOperation -fqdn $displayName -deploymentResponse $output Write-Output (Get-LocalizedString -Key "Deployment status for machine '{0}' : '{1}'" -ArgumentList $displayName, $status) + Publish-AzureTelemetry -deploymentResponse $output -jobId $jobId + if($status -ne "Passed") { $envOperationStatus = "Failed" @@ -161,12 +194,8 @@ else } } } - if($envOperationStatus -ne "Passed") { - foreach ($error in $dtlsdkErrors) { - Write-Telemetry "DTLSDK_Error" $error - } $errorMessage = (Get-LocalizedString -Key 'Deployment on one or more machines failed.') throw $errorMessage diff --git a/Tasks/PowerShellOnTargetMachines/task.json b/Tasks/PowerShellOnTargetMachines/task.json index 98a1f8c8fdbe..eb1a372582ae 100644 --- a/Tasks/PowerShellOnTargetMachines/task.json +++ b/Tasks/PowerShellOnTargetMachines/task.json @@ -13,7 +13,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 47 + "Patch": 51 }, "minimumAgentVersion": "1.104.0", "groups": [ diff --git a/Tasks/PowerShellOnTargetMachines/task.loc.json b/Tasks/PowerShellOnTargetMachines/task.loc.json index 9fe8d36c8c60..3cb94b414295 100644 --- a/Tasks/PowerShellOnTargetMachines/task.loc.json +++ b/Tasks/PowerShellOnTargetMachines/task.loc.json @@ -13,7 +13,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 47 + "Patch": 51 }, "minimumAgentVersion": "1.104.0", "groups": [ diff --git a/Tasks/WindowsMachineFileCopy/task.json b/Tasks/WindowsMachineFileCopy/task.json index cbedf375786c..330a15b91fd0 100644 --- a/Tasks/WindowsMachineFileCopy/task.json +++ b/Tasks/WindowsMachineFileCopy/task.json @@ -13,7 +13,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 41 + "Patch": 43 }, "minimumAgentVersion": "1.104.0", "groups": [ diff --git a/Tasks/WindowsMachineFileCopy/task.loc.json b/Tasks/WindowsMachineFileCopy/task.loc.json index 28e7180a5f7f..3bb81168b784 100644 --- a/Tasks/WindowsMachineFileCopy/task.loc.json +++ b/Tasks/WindowsMachineFileCopy/task.loc.json @@ -13,7 +13,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 41 + "Patch": 43 }, "minimumAgentVersion": "1.104.0", "groups": [