【发布时间】:2015-12-28 22:48:17
【问题描述】:
我正在尝试使 PowerShell 脚本中的某个结果使构建过程失败,但它对我不起作用。我正在使用 TFS 2015 中的新构建操作并尝试了以下选项:
- Logging commands
- 退出 1
我确实在步骤的日志窗口中看到了红色文本,并且在构建概述中标记了“问题”,但构建结果仍然是绿色:“构建成功”
我想使用脚本中的失败来使构建失败,从而使用失败构建的警报发送电子邮件。
编辑:包括 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();
}
$res = $_.Exception.Response
}
$printCode=[int]$res.StatusCode
Write-Host "Result StatusCode:" $res.StatusCode "(" $printCode ")"
If ([int]$res.StatusCode -eq 200)
{
Write-Host "##vso[task.complete result=Succeeded;]Done"
}
Else
{
Write-Host "##vso[task.logissue type=error;]Test error: " $res
Write-Host "##vso[task.complete result=Failed;]Error testing if demo site is up"
exit 1
}
【问题讨论】:
-
您能分享您的 PowerShell 脚本以便我们重现吗?
-
我已编辑问题以包含脚本
标签: powershell tfs-2015