我试图在PowerShell脚本中使某个结果在构建过程中失败,但它对我不起作用.我正在使用TFS 2015中的新构建操作并尝试以下选项:
我确实在步骤的日志窗口中获得了红色文本,并在构建概述中标记了"问题",但构建结果仍为绿色:"构建成功"
我想使用脚本中的失败来使构建失败,从而使用失败构建的警报发送电子邮件.
编辑:包括PS脚本:
Param(
[string]$url
)
if ($url -eq '')
{
#use default value
$url = 'https://myurl.com'
}
$req = [system.Net.WebRequest]::Create($url)
$req.Timeout = 60000 * 5 # = 5 minutes
try
{
Write-Host "Try to get response from url:" $url
$res = $req.GetResponse()
Write-Host "Closing the connection"
$req.Close() # close the connection
}
catch [System.Net.WebException]
{
Write-Host "Got an exception"
Write-Host "##vso[task.logissue type=error;]Exception: " $_.Exception
if ($_.response) # try to close the connection
{
$_.response.Close();
} …Run Code Online (Sandbox Code Playgroud)