From ab32b4d71b088c47cf198c35ab5cc6ee67fe67a3 Mon Sep 17 00:00:00 2001 From: Roshan Kumar Date: Wed, 21 Feb 2018 15:57:21 +0530 Subject: [PATCH 1/8] after resolving conflict with m123 --- .../PowerShellJob.ps1 | 51 ++++++++++++++++++- .../PowerShellOnTargetMachines.ps1 | 49 ++++++++++++++++++ Tasks/PowerShellOnTargetMachines/task.json | 2 +- .../PowerShellOnTargetMachines/task.loc.json | 2 +- 4 files changed, 101 insertions(+), 3 deletions(-) diff --git a/Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 b/Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 index 26c2e19cbce6..177c8f7cbb9c 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 + $deploymentResponse | Add-Member "VmUuidHash" $VmUuidHash + } + catch + { + Write-Verbose "Error during fetching telemetry = $_" + $deploymentResponse | Add-Member "TelemetryError" $_ + } + Write-Output $deploymentResponse } diff --git a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 index fcad9063f49b..fcf791ecce98 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 @@ -64,7 +65,52 @@ if ($enableDetailedLoggingString -ne "true") # Telemetry Import-Module $PSScriptRoot\ps_modules\TelemetryHelper +# Import all the dlls and modules which have cmdlets we need +Import-Module "$PSScriptRoot\DeploymentUtilities\Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Internal.psm1" +Import-Module "$PSScriptRoot\DeploymentUtilities\Microsoft.TeamFoundation.DistributedTask.Task.Deployment.dll" +function Write-DTLServiceDeprecationMessageIfRequired +{ + param([string]$machine) + + try + { + $jsonValue = ConvertFrom-Json $environmentName -ErrorAction Stop; + $validJson = $true; + } + catch + { + $validJson = $false; + } + + if(!$validJson) + { + if(-not($machine.Contains('.')) -and -not($machine.Contains(':')) -and -not($machine.Contains(","))) + { + write-error "Deployments using 'test hub: machine groups' is no longer supported. Refer to https://go.microsoft.com/fwlink/?LinkID=799742&clcid=0x409 for more information or get help from Developer Community [https://developercommunity.visualstudio.com/spaces/21/index.html]." + } + } +} + +function Publish-Azure-Telemetry + { + param([object] $deploymentResponse, [string] $jobId) + if($deploymentResponse){ + $jsonString = -join("{" , + "`"IsAzureVm`" : `"$($deploymentResponse.IsAzureVm)`"" , + "," , + "`"VmUuidHash`" : `"$($deploymentResponse.VmUuidHash)`"" , + "," , + "`"TelemetryError`" : `"$($deploymentResponse.TelemetryError)`"" , + "," , + "`"JobId`" : `"$jobId`"" , + "}") + } + + $telemetryString ="##vso[telemetry.publish area=TaskHub;feature=PowerShellOnTargetMachines]$jsonString" + Write-Host $telemetryString + } + try { $connection = Get-VssConnection -TaskContext $distributedTaskContext @@ -105,6 +151,7 @@ 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-Azure-Telemetry -deploymentResponse $deploymentResponse -jobId $jobId if ($status -ne "Passed") { @@ -145,6 +192,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-Azure-Telemetry -deploymentResponse $output -jobId $jobId + if($status -ne "Passed") { $envOperationStatus = "Failed" 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": [ From 96c1023c453c4e84b1cad02b444d248c0dce693b Mon Sep 17 00:00:00 2001 From: Roshan Kumar Date: Mon, 26 Feb 2018 17:29:18 +0530 Subject: [PATCH 2/8] review incorporated --- .../PowerShellOnTargetMachines.ps1 | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 index fcf791ecce98..1f596f773a07 100644 --- a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 +++ b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 @@ -92,19 +92,30 @@ function Write-DTLServiceDeprecationMessageIfRequired } } -function Publish-Azure-Telemetry +function Publish-AzureTelemetry { - param([object] $deploymentResponse, [string] $jobId) + param([object] $deploymentResponse, + [string] $jobId ) if($deploymentResponse){ - $jsonString = -join("{" , - "`"IsAzureVm`" : `"$($deploymentResponse.IsAzureVm)`"" , - "," , - "`"VmUuidHash`" : `"$($deploymentResponse.VmUuidHash)`"" , - "," , - "`"TelemetryError`" : `"$($deploymentResponse.TelemetryError)`"" , - "," , - "`"JobId`" : `"$jobId`"" , - "}") + $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" @@ -151,7 +162,7 @@ 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-Azure-Telemetry -deploymentResponse $deploymentResponse -jobId $jobId + Publish-AzureTelemetry -deploymentResponse $deploymentResponse -jobId $jobId if ($status -ne "Passed") { @@ -192,7 +203,7 @@ else Write-ResponseLogs -operationName $deploymentOperation -fqdn $displayName -deploymentResponse $output Write-Output (Get-LocalizedString -Key "Deployment status for machine '{0}' : '{1}'" -ArgumentList $displayName, $status) - Publish-Azure-Telemetry -deploymentResponse $output -jobId $jobId + Publish-AzureTelemetry -deploymentResponse $output -jobId $jobId if($status -ne "Passed") { From df718b0908373d301b6e7a06f7327f2f0d246382 Mon Sep 17 00:00:00 2001 From: Roshan Kumar Date: Wed, 14 Mar 2018 18:33:34 +0530 Subject: [PATCH 3/8] Force member update --- Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 b/Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 index 177c8f7cbb9c..c4ed66ee733c 100644 --- a/Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 +++ b/Tasks/PowerShellOnTargetMachines/PowerShellJob.ps1 @@ -94,13 +94,13 @@ param ( } } } - $deploymentResponse | Add-Member "IsAzureVm" $IsAzureVm - $deploymentResponse | Add-Member "VmUuidHash" $VmUuidHash + $deploymentResponse | Add-Member "IsAzureVm" $IsAzureVm -Force + $deploymentResponse | Add-Member "VmUuidHash" $VmUuidHash -Force } catch { Write-Verbose "Error during fetching telemetry = $_" - $deploymentResponse | Add-Member "TelemetryError" $_ + $deploymentResponse | Add-Member "TelemetryError" $_ -Force } Write-Output $deploymentResponse From bfd69f2a89641cdcc48949fb3d3afe27dc50fd3d Mon Sep 17 00:00:00 2001 From: asranja Date: Thu, 5 Apr 2018 17:31:22 +0530 Subject: [PATCH 4/8] ashish change for dtlsdk_erro --- .../PowerShellOnTargetMachines.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 index 1f596f773a07..6b70d257e299 100644 --- a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 +++ b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 @@ -166,7 +166,6 @@ if($runPowershellInParallel -eq "false" -or ( $resources.Count -eq 1 ) ) if ($status -ne "Passed") { - Write-Telemetry "DTLSDK_Error" $deploymentResponse.DeploymentSummary Write-Verbose $deploymentResponse.Error.ToString() $errorMessage = $deploymentResponse.Error.Message throw $errorMessage @@ -220,13 +219,9 @@ 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 From 2a0bd2b821e0c9743b332cb691bb6d20e72ca603 Mon Sep 17 00:00:00 2001 From: Roshan Kumar Date: Mon, 9 Apr 2018 14:04:32 +0530 Subject: [PATCH 5/8] window filw copy task version incresed --- Tasks/WindowsMachineFileCopy/task.json | 2 +- Tasks/WindowsMachineFileCopy/task.loc.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tasks/WindowsMachineFileCopy/task.json b/Tasks/WindowsMachineFileCopy/task.json index cbedf375786c..68a5ffa344d9 100644 --- a/Tasks/WindowsMachineFileCopy/task.json +++ b/Tasks/WindowsMachineFileCopy/task.json @@ -13,7 +13,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 41 + "Patch": 42 }, "minimumAgentVersion": "1.104.0", "groups": [ diff --git a/Tasks/WindowsMachineFileCopy/task.loc.json b/Tasks/WindowsMachineFileCopy/task.loc.json index 28e7180a5f7f..a3838ae6f28c 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": 42 }, "minimumAgentVersion": "1.104.0", "groups": [ From 0debc5177cb83e7f67ffbdbc2cd8f5557f922788 Mon Sep 17 00:00:00 2001 From: Roshan Kumar Date: Mon, 9 Apr 2018 14:05:06 +0530 Subject: [PATCH 6/8] ashish change for dtlsdk_erro --- Tasks/WindowsMachineFileCopy/task.json | 2 +- Tasks/WindowsMachineFileCopy/task.loc.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tasks/WindowsMachineFileCopy/task.json b/Tasks/WindowsMachineFileCopy/task.json index 68a5ffa344d9..330a15b91fd0 100644 --- a/Tasks/WindowsMachineFileCopy/task.json +++ b/Tasks/WindowsMachineFileCopy/task.json @@ -13,7 +13,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 42 + "Patch": 43 }, "minimumAgentVersion": "1.104.0", "groups": [ diff --git a/Tasks/WindowsMachineFileCopy/task.loc.json b/Tasks/WindowsMachineFileCopy/task.loc.json index a3838ae6f28c..3bb81168b784 100644 --- a/Tasks/WindowsMachineFileCopy/task.loc.json +++ b/Tasks/WindowsMachineFileCopy/task.loc.json @@ -13,7 +13,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 42 + "Patch": 43 }, "minimumAgentVersion": "1.104.0", "groups": [ From 9f7047c97923e40a57b9ef9e70d75a9b9e4d4e5a Mon Sep 17 00:00:00 2001 From: Roshan Kumar Date: Mon, 9 Apr 2018 14:27:50 +0530 Subject: [PATCH 7/8] Removing unwanted changes --- .../PowerShellOnTargetMachines.ps1 | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 index 6b70d257e299..2edb43800fe9 100644 --- a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 +++ b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 @@ -65,32 +65,6 @@ if ($enableDetailedLoggingString -ne "true") # Telemetry Import-Module $PSScriptRoot\ps_modules\TelemetryHelper -# Import all the dlls and modules which have cmdlets we need -Import-Module "$PSScriptRoot\DeploymentUtilities\Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Internal.psm1" -Import-Module "$PSScriptRoot\DeploymentUtilities\Microsoft.TeamFoundation.DistributedTask.Task.Deployment.dll" - -function Write-DTLServiceDeprecationMessageIfRequired -{ - param([string]$machine) - - try - { - $jsonValue = ConvertFrom-Json $environmentName -ErrorAction Stop; - $validJson = $true; - } - catch - { - $validJson = $false; - } - - if(!$validJson) - { - if(-not($machine.Contains('.')) -and -not($machine.Contains(':')) -and -not($machine.Contains(","))) - { - write-error "Deployments using 'test hub: machine groups' is no longer supported. Refer to https://go.microsoft.com/fwlink/?LinkID=799742&clcid=0x409 for more information or get help from Developer Community [https://developercommunity.visualstudio.com/spaces/21/index.html]." - } - } -} function Publish-AzureTelemetry { From 5b48701350dca9ca35d0bb7a48b8841f7595ddbc Mon Sep 17 00:00:00 2001 From: Roshan Kumar Date: Mon, 9 Apr 2018 17:29:13 +0530 Subject: [PATCH 8/8] braces --- Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 index 2edb43800fe9..c47976b38605 100644 --- a/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 +++ b/Tasks/PowerShellOnTargetMachines/PowerShellOnTargetMachines.ps1 @@ -193,7 +193,7 @@ else } } } - +} if($envOperationStatus -ne "Passed") {