tfsbuild - 有什么方法可以杀死(停止)从代码构建的 TFS 2017 团队?
问题描述
我有一个 TFS2017 版本,第一步是检查 c:\ 驱动器上是否存在所需的文件夹。该文件夹是构建正确完成的先决条件,因此如果该文件夹不存在,我想显示一条错误消息并终止构建。我试过返回 -1 但这并不能阻止构建继续。有没有办法以编程方式杀死正在运行的构建?
这是我当前检查文件夹的 PS 脚本。我已经用 xxxx 代替了我的实际文件夹名称(以保护无辜的 ;-):
param([string]$DirSuffix="x")
<#
This script is called by the xxxx build to make sure that the GVB folder
exists on c:\ before the build is run. It should be called by passing in the
directory suffix (e.g. \xxxx 2.3.1). I can't figure out how to
kill the build
if the folder doesn't exist so I'm just going to write multiple errors to
the console and hope that the builder see them and cancels the build.
#>
[string] $WholeDirectory='C:\XXXX' + $DirSuffix
if (-NOT [IO.Directory]::Exists($WholeDirectory))
{
Write-Host Directory $WholeDirectory does not exist - please make sure that the xxxx build has run first!!!
Write-Host "##vso[task.logissue type=error;] Directory $WholeDirectory does not exist - please make sure that the xxxx build has run
return -1
}
解决方案
Instead of using return -1
, you should 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 if the folder doesn't exist and judge if you have to fail the task or not.
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
Also remember to check the Fail on Standard Error option in your powershell task and also select the condition Only when all previous tasks have succeeded to Run this task for the build task which next to powershell in your build pipeline. This will kill the build process.
推荐阅读
- java - 在其构造函数中调用另一个类的类的 Mockito 测试用例,其中为 Java 中的旧应用程序分配了 3 个变量
- javascript - 单击时 HTML/CSS 更改按钮的颜色,包括其他按钮
- ios - 日期格式化程序中的艰难时期
- php - 未找到接口“Illuminate\Contracts\Support\DeferrableProvider”
- nginx - Nginx:删除单个查询字符串参数
- android - 未向应用程序提供运营商特权
- docker - Docker 在创建之前删除图像和容器
- hosting - 将外部域映射到 Google Cloud Hosting 的问题
- python-3.x - 绘图:如何在双 y 图中分隔 xticks?
- bash - mongo c 驱动程序 ./configure; 没有相应的文件和目录