如何在 Team Build 2013 Post-Test 脚本中检测测试运行是否成功? [英] How do I detect if the test run was successful in a Team Build 2013 Post-Test script?

查看:56
本文介绍了如何在 Team Build 2013 Post-Test 脚本中检测测试运行是否成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 TFS 2013 中有一个构建配置,可以生成版本化的构建工件.此构建使用开箱即用的流程模板工作流.我想在单元测试失败的情况下销毁构建工件,只留下日志文件.我有一个测试后的 powershell 脚本.如何检测此脚本中的测试失败?

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?

推荐答案

(根据更多信息更新)

这样做的方法是使用环境变量并在您的 PowerShell 脚本中读取它们.不幸的是,powershell 脚本每次都在一个新进程中运行,因此您不能依赖填充的环境变量.

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.

也就是说,有一种解决方法,因此您仍然可以获得这些值.它涉及在您的 PowerShell 脚本开始时调用一个小实用程序,如本博文所述:http://blogs.msmvps.com/vstsblog/2014/05/20/getting-the-compile-and-test-status-as-environment-variables-when-extending-tf-build-using-scripts/

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/

这篇关于如何在 Team Build 2013 Post-Test 脚本中检测测试运行是否成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆