【发布时间】:2019-03-22 00:11:09
【问题描述】:
我想创建一个 Powershell 脚本,该脚本既可以在 TFS 上的构建代理上下文中执行,也可以在本地执行。在 TFS 上,可以使用各种predefined build variables,例如$(Build.SourcesDirectory)。同时,该脚本在源代码树中也可用,因此我希望能够在本地运行它,其中未设置这些变量。我发现回退到默认值的最短方法是以下 Try..Catch 块与令人不安的长异常类型:
Try {
$SourcesDirectory = $(Build.SourcesDirectory)
}
Catch [System.Management.Automation.CommandNotFoundException] {
$SourcesDirectory = "..\..\Local\Path\To\Sources\Directory"
}
Write-Output $SourcesDirectory
有没有“更好”的方法来完成这个?
【问题讨论】:
标签: powershell tfs