Skip to content

Commit

Permalink
Merge pull request #4700 from Microsoft/users/dsinghal/tfsu2fix
Browse files Browse the repository at this point in the history
TWUsers/dsinghal/tfsu2fix
  • Loading branch information
dpksinghal authored Jun 30, 2017
2 parents 2b5b241 + bbe4f96 commit 4068e88
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
44 changes: 40 additions & 4 deletions Tasks/DeployVisualStudioTestAgent/InstallTestAgent.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function ExtractAgentArchive ($SetupArchive, $Destination) {
function ExtractAgentArchive ($SetupArchive, $Destination) {
Write-Verbose "Extracting the archive $SetupArchive"
Try {
Add-Type -AssemblyName System.IO.Compression.FileSystem
Expand All @@ -25,9 +25,29 @@ function InstallTestAgent2017 {
}

# First we need to install the certificates for TA 2017
$SetupDir = Split-Path -Path $SetupPath
Write-Verbose "Installing test agent certificates"
Get-ChildItem -Path "$SetupDir\certificates\*.p12" -ErrorAction SilentlyContinue | Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -Exportable
$SetupDir = Split-Path -Path $SetupPath
$certFiles = Get-ChildItem -Path "$SetupDir\certificates\*.p12" -ErrorAction SilentlyContinue
if($certFiles -and $certFiles.Length -gt 0)
{
$osVersion = [environment]::OSVersion.Version
Write-Verbose "Installing test agent certificates" -Verbose
if ($osVersion.Major -eq "6" -and $osVersion.Minor -eq "1") {
## Windows 7 SP1. Import-PfxCertificate is not present in windows 7
Write-Verbose "Installing agent certificate(s) for Windows 7." -Verbose
foreach($certFile in $certFiles)
{
Import-PfxCertificateWin7 -FilePath $certFile.FullName -CertRootStore "CurrentUser" -CertStore "My"
}
}
else {
Write-Verbose "Installing agent certificate(s) for Windows 8 or above." -Verbose
$certFiles | Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -Exportable
}
Write-Verbose "Successfully installed the agent certificate." -Verbose
}
else {
Write-Verbose "No test agent certificate found." -Verbose
}

$p = New-Object System.Diagnostics.Process
$Processinfo = New-Object System.Diagnostics.ProcessStartInfo
Expand All @@ -50,6 +70,22 @@ function InstallTestAgent2017 {
return $p.ExitCode
}

function Import-PfxCertificateWin7 {
param
(
[Parameter (Mandatory=$true, ValueFromPipelineByPropertyName)]
[String]$FilePath,
[String]$CertRootStore="CurrentUser",
[String]$CertStore="My"
)
$pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
$pfx.import($FilePath, $pfxPass, "Exportable")
$store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore)
$store.open("MaxAllowed")
$store.add($pfx)
$store.close()
}

function Install-Product($SetupPath, $ProductVersion, $Update) {
$exitCode = 0

Expand Down
3 changes: 2 additions & 1 deletion Tasks/DeployVisualStudioTestAgent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ To learn more about the general usage of the task, please see https://msdn.micro

### Prerequisites
The task requires:
- .NET 4.6.1 on Windows8 or Windows 2K8R2
- .NET 4.6.1 on Windows7 or Windows 2K8R2
- PowerShell 3 or newer
- Test machines should have PSRemoting enabled (run 'Enable-PSRemoting' on Windows Powershell)
### WinRM setup
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.
Expand Down
11 changes: 7 additions & 4 deletions Tasks/DeployVisualStudioTestAgent/TestAgentConfiguration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,28 @@

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

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

Start-ScheduledTask -TaskName "DTA" -OutVariable out -ErrorVariable err | Out-Null
Write-Verbose "Starting scheduled task output: $out error: $err" -Verbose

Start-Sleep -Seconds 30
$p = Get-Process -Name "DTAExecutionHost"
Unregister-ScheduledTask -TaskName "DTA" -Confirm:$false -ErrorAction SilentlyContinue
}

Start-Sleep -Seconds 10

$p = Get-Process -Name "DTAExecutionHost" -ErrorAction SilentlyContinue
if ($p) {
return 0
}
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DeployVisualStudioTestAgent/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 2,
"Minor": 1,
"Patch": 7
"Patch": 8
},
"runsOn": [
"Agent"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DeployVisualStudioTestAgent/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 2,
"Minor": 1,
"Patch": 7
"Patch": 8
},
"runsOn": [
"Agent"
Expand Down

0 comments on commit 4068e88

Please sign in to comment.