Skip to content

Commit 4068e88

Browse files
authored
Merge pull request microsoft#4700 from Microsoft/users/dsinghal/tfsu2fix
TWUsers/dsinghal/tfsu2fix
2 parents 2b5b241 + bbe4f96 commit 4068e88

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

Tasks/DeployVisualStudioTestAgent/InstallTestAgent.ps1

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function ExtractAgentArchive ($SetupArchive, $Destination) {
1+
function ExtractAgentArchive ($SetupArchive, $Destination) {
22
Write-Verbose "Extracting the archive $SetupArchive"
33
Try {
44
Add-Type -AssemblyName System.IO.Compression.FileSystem
@@ -25,9 +25,29 @@ function InstallTestAgent2017 {
2525
}
2626

2727
# First we need to install the certificates for TA 2017
28-
$SetupDir = Split-Path -Path $SetupPath
29-
Write-Verbose "Installing test agent certificates"
30-
Get-ChildItem -Path "$SetupDir\certificates\*.p12" -ErrorAction SilentlyContinue | Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -Exportable
28+
$SetupDir = Split-Path -Path $SetupPath
29+
$certFiles = Get-ChildItem -Path "$SetupDir\certificates\*.p12" -ErrorAction SilentlyContinue
30+
if($certFiles -and $certFiles.Length -gt 0)
31+
{
32+
$osVersion = [environment]::OSVersion.Version
33+
Write-Verbose "Installing test agent certificates" -Verbose
34+
if ($osVersion.Major -eq "6" -and $osVersion.Minor -eq "1") {
35+
## Windows 7 SP1. Import-PfxCertificate is not present in windows 7
36+
Write-Verbose "Installing agent certificate(s) for Windows 7." -Verbose
37+
foreach($certFile in $certFiles)
38+
{
39+
Import-PfxCertificateWin7 -FilePath $certFile.FullName -CertRootStore "CurrentUser" -CertStore "My"
40+
}
41+
}
42+
else {
43+
Write-Verbose "Installing agent certificate(s) for Windows 8 or above." -Verbose
44+
$certFiles | Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -Exportable
45+
}
46+
Write-Verbose "Successfully installed the agent certificate." -Verbose
47+
}
48+
else {
49+
Write-Verbose "No test agent certificate found." -Verbose
50+
}
3151

3252
$p = New-Object System.Diagnostics.Process
3353
$Processinfo = New-Object System.Diagnostics.ProcessStartInfo
@@ -50,6 +70,22 @@ function InstallTestAgent2017 {
5070
return $p.ExitCode
5171
}
5272

73+
function Import-PfxCertificateWin7 {
74+
param
75+
(
76+
[Parameter (Mandatory=$true, ValueFromPipelineByPropertyName)]
77+
[String]$FilePath,
78+
[String]$CertRootStore="CurrentUser",
79+
[String]$CertStore="My"
80+
)
81+
$pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
82+
$pfx.import($FilePath, $pfxPass, "Exportable")
83+
$store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore)
84+
$store.open("MaxAllowed")
85+
$store.add($pfx)
86+
$store.close()
87+
}
88+
5389
function Install-Product($SetupPath, $ProductVersion, $Update) {
5490
$exitCode = 0
5591

Tasks/DeployVisualStudioTestAgent/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ To learn more about the general usage of the task, please see https://msdn.micro
66

77
### Prerequisites
88
The task requires:
9-
- .NET 4.6.1 on Windows8 or Windows 2K8R2
9+
- .NET 4.6.1 on Windows7 or Windows 2K8R2
10+
- PowerShell 3 or newer
1011
- Test machines should have PSRemoting enabled (run 'Enable-PSRemoting' on Windows Powershell)
1112
### WinRM setup
1213
This task uses the [Windows Remote Management](https://msdn.microsoft.com/en-us/library/aa384426.aspx) (WinRM) to access domain-joined or workgroup, on-premises physical or virtual machines.

Tasks/DeployVisualStudioTestAgent/TestAgentConfiguration.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,28 @@
162162

163163
$rootFolder = $ScheduleObject.GetFolder('\') #'
164164
$newTask = $rootFolder.RegisterTaskDefinition("DTA", $TaskDefinition, 6, '', '', 3)
165+
Write-Verbose "Starting scheduled task on Windows 7." -Verbose
166+
Start-Sleep -Seconds 30
167+
$p = Get-Process -Name "DTAExecutionHost"
168+
$rootFolder.DeleteTask("DTA", 0)
165169
}
166170
else {
167171
# Windows 8 or above
168172
$action = New-ScheduledTaskAction -Execute "$SetupPath\DTAExecutionHost.exe" -Argument $dtaArgs
169173
$trigger = New-ScheduledTaskTrigger -AtLogOn
170-
$exePath = "$SetupPath\DTAExecutionHost.exe $dtaArgs"
171174

172175
Unregister-ScheduledTask -TaskName "DTA" -Confirm:$false -OutVariable out -ErrorVariable err -ErrorAction SilentlyContinue | Out-Null
173176
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "DTA" -Description "DTA UI" -RunLevel Highest -OutVariable out -ErrorVariable err | Out-Null
174177
Write-Verbose "Registering scheduled task output: $out error: $err" -Verbose
175178

176179
Start-ScheduledTask -TaskName "DTA" -OutVariable out -ErrorVariable err | Out-Null
177180
Write-Verbose "Starting scheduled task output: $out error: $err" -Verbose
181+
182+
Start-Sleep -Seconds 30
183+
$p = Get-Process -Name "DTAExecutionHost"
178184
Unregister-ScheduledTask -TaskName "DTA" -Confirm:$false -ErrorAction SilentlyContinue
179185
}
180-
181-
Start-Sleep -Seconds 10
182186

183-
$p = Get-Process -Name "DTAExecutionHost" -ErrorAction SilentlyContinue
184187
if ($p) {
185188
return 0
186189
}

Tasks/DeployVisualStudioTestAgent/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": 1,
16-
"Patch": 7
16+
"Patch": 8
1717
},
1818
"runsOn": [
1919
"Agent"

Tasks/DeployVisualStudioTestAgent/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": 1,
16-
"Patch": 7
16+
"Patch": 8
1717
},
1818
"runsOn": [
1919
"Agent"

0 commit comments

Comments
 (0)