Visual Studio Online

Trigger Usetrace testing for new code commits in Visual Studio Online

Arto Vuori avatar
Written by Arto Vuori
Updated over a week ago

This integration launches testing whenever there’s a new code push to the Visual Studio Online (VSO) repository.

Steps to integrate Visual Studio Online:

  1. Push the script “UsetraceRun.ps1” (find example below) to your version control in VSO.

  2. Login to Visual Studio Online

  3. Add new build definition BUILD->[+]->Empty (start with empty definition)

  4. Add Build Step…->Utility->PowerShell (run a powershell script)

  5. Build->Powershell: Script filename -> “UsetraceRun.ps1”

  6. Triggers->Check Continuous integration (build each check-in)

  7. Save “Usetrace Run”

If any of the traces fail, the build will fail in VSO.

Example for “UsetraceRun.ps1” script

Copy & paste the script to your version control and replace YOUR-PROJECT-ID with the ID from Settings->Project.

$projectId = "YOUR-PROJECT-ID"
$pollTimeoutMinutes = 20
$startBatchResource = "$projectId/execute_all"
$startBatchRequest = @"
"@$batchId = Invoke-RestMethod -ContentType "application/json" -Method Post -Uri $startBatchResource -Body $startBatchRequest
Write-Output "Batch ID: $batchId"$timeout = new-timespan -Minutes $pollTimeoutMinutes
$sw = [diagnostics.stopwatch]::StartNew()while ($sw.elapsed -lt $timeout){
    $batchStatusResource = "$batchId/xunit"
    $batchStatus = Invoke-RestMethod -ContentType "application/json" -Method Get -Uri $batchStatusResource
    $ts = Get-Date -Format
    Write-Output "$ts Batch is running..."
    if ($batchStatus.statusCode -ne 404){
        $ts = Get-Date -Format
        Write-Output "$ts Batch completed."
        $batchReport = $batchStatus
        [int]$errorCount = [convert]::ToInt32($batchReport.testSuite.errors, 10)
        [int]$failureCount = [convert]::ToInt32($batchReport.testSuite.failures, 10)
        Write-Output $batchReport.testSuite
        if($errorCount -gt 0 -or $failureCount -gt 0){
            throw "Batch failed!"
        exit 0
    start-sleep -seconds 5
throw "Batch timed out!"
Did this answer your question?