Created
November 1, 2016 16:54
-
-
Save Sam-Martin/54decf2ebc0601144823fd05977f3709 to your computer and use it in GitHub Desktop.
Run Pester Tests Remotely
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$tests = Get-Content "%teamcity.build.checkoutDir%\TeamCity-Build-Agents.tests.ps1" | Out-String | |
$scriptblock = { | |
param($script) | |
$scriptFile = "$env:temp\TeamCity-Build-Agents.tests.ps1" | |
Set-Content $scriptFile -Value $script | |
Invoke-Pester -Script $scriptFile -PassThru 6> $null 2> $null | |
} | |
$BuildAgents = @( | |
'tc-buildagent-01', | |
'tc-buildagent-02', | |
'tc-buildagent-03', | |
) | |
$results = Invoke-Command -ComputerName $BuildAgents -ScriptBlock $scriptblock -ArgumentList $tests | |
foreach($result in $results){ | |
Write-Host "`r`n`r`n$($result.pscomputername) $($result.failedcount) task(s) failed, $($result.passedcount) test(s) passed" | |
# Print out failure messages | |
foreach($failure in $($result.TestResult | ?{$_.passed -eq $false})){ | |
Write-Host "`t$($failure.Describe) - $($failure.name) - $($failure.result) `r`n $($failure.failuremessage)" | |
} | |
} | |
# Exit 1 to fail the TC job if any tests failed | |
if(($results | Measure-Object -sum failedcount).sum -gt 0){ | |
exit 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment