Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect if the test run was successful in a Team Build 2013 Post-Test script?

I have a build configuration in TFS 2013 that produces versioned build artifacts. This build uses the out of the box process template workflow. I want to destroy the build artifacts in the event that unit tests fail leaving only the log files. I have a Post-Test powershell script. How do I detect the test failure in this script?

Here is the relevant cleanup method in my post-test script:

function Clean-Files($dir){
    if (Test-Path -path $dir) { rmdir $dir\* -recurse -force -exclude logs,"$NewVersion" }
    if(0 -eq 1) { rmdir $dir\* -recurse -force -exclude logs }
}
Clean-Files "$Env:TF_BUILD_BINARIESDIRECTORY\"

How do I tests for test success in the function?

like image 896
NotMyself Avatar asked Nov 07 '14 19:11

NotMyself


1 Answers

(Updated based on more information)

The way to do this is to use environment variables and read them in your PowerShell script. Unfortunately the powershell scripts are run in a new process each time so you can't rely on the environment variables being populated.

That said, there is a workaround so you can still get those values. It involves calling a small utility at the start of your powershell script as described in this blog post: http://blogs.msmvps.com/vstsblog/2014/05/20/getting-the-compile-and-test-status-as-environment-variables-when-extending-tf-build-using-scripts/

like image 190
Richard Banks Avatar answered Oct 04 '22 01:10

Richard Banks