有没有办法从代码中杀死(停止)TFS 2017团队构建?

时间:2018-06-05 16:17:37

标签: tfsbuild tfs2017

我有一个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
}

2 个答案:

答案 0 :(得分:0)

如果您有多个代理,并且只想在需要文件夹的代理上运行构建,则可以将此文件夹添加到&#34;功能&#34; (Click here to photo), 在构建定义中,您需要指定&#34;需求&#34;它是必需的(Click here to photo)。

答案 1 :(得分:0)

您应该使用Logging Commands退出代码来使构建任务失败,而不是使用return -1,然后使整个构建失败。

 Write-Error "Some error"
 exit 1

添加powershell任务以捕获文件夹是否存在并判断是否必须使任务失败。

有关如何使vNext构建失败的更多详细信息,请参阅此问题:How to fail the build from a PowerShell task in TFS 2015

另请记住检查您的powershell任务中的标准错误失败选项,并选择条件仅当所有先前任务都成功才能为构建运行此任务在构建管道中的powershell旁边的任务。这将终止构建过程。

enter image description here