I have a simple build process in TFS 2017 using CI/CD demo as described in https://msdn.microsoft.com/en-us/powershell/dsc/dsccicd
The Build definition contains four steps:
When Pester test fails , I would like entire build to fail. At the moment build succeeds even when Published Test results show as failed ( In Issues section of Build Details). I don't see how can I force entire build to fail looking at the Build definition parameters.
I'm not using TFS, but in my build process test failures trigger the build to fail by outputting an error.
This is done by adding the -PassThru
switch to Invoke-Peter
and sending the results of the command to a variable:
$TestResults = Invoke-Pester -Path .\Tests -PassThru
Then writing an error if there are any failed tests:
if($TestResults.FailedCount -gt 0)
{
Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed"
}
And then in the script after using Invoke-PSake
:
exit ( [int]( -not $psake.build_success ) )
You could use Logging Commands and exit code to fail a build task, then fail the entire build.
Write-Error ("Some error")
exit 1
Add a powershell task to catch the published Tests logs or status to judge if you have to fail the task. More details about how to fail a vNext build please refer this question: How to fail the build from a PowerShell task in TFS 2015
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With