[英]Adding errors to build summary from PowerShell script running in VSTS
In VSTS, I am using a PowerShell task to run one of my script. 在VSTS中,我使用PowerShell任务来运行我的一个脚本。 The script contains the following:
该脚本包含以下内容:
Write-Error 'error 1'
Write-Error 'error 2'
Since the Write-Error cmdlet writes on stderr, these messages get reported in the VSTS web interface: 由于Write-Error cmdlet在stderr上写入,因此会在VSTS Web界面中报告这些消息:
I would like to improve on this output. 我想改进这个输出。 The improvements that I am looking for is:
我正在寻找的改进是:
Instead of calling Write-Error, is there another function that I can call from my script to add an error to the build summary page? 而不是调用Write-Error,我可以从我的脚本调用另一个函数来向构建摘要页面添加错误吗?
I saw the function Write-VstsTaskError but unfortunately it can only be called from a VSTS task. 我看到函数Write-VstsTaskError但不幸的是它只能从VSTS任务调用。 It cannot be called from my script.
它无法从我的脚本中调用。
The recommended way to do this is using VSO logging commands as discussed in the GitHub issue below. 建议的方法是使用VSO日志记录命令,如下面的GitHub问题中所述。
Is it possible to raise and display build warnings from build steps using TFS 2015? 是否可以使用TFS 2015从构建步骤中引发和显示构建警告?
For example: 例如:
Write-Host "##vso[task.logissue type=warning;]Test warning"
Write-Host "##vso[task.logissue type=error;]Test error"
After lots of trial and error, I was able to solve problem #1. 经过大量的反复试验,我能够解决问题#1。 The VSTS build displays a red X for each entry in stderr that is seperated by an entry on stdout.
VSTS构建为stderr中的每个条目显示一个红色X,该条目由stdout上的条目分隔。 So, if I change my script to the following:
所以,如果我将脚本更改为以下内容:
Write-Error 'Error 1'
Write-Host '***'
Write-Error 'Error 2'
Write-Host '***'
I now have one red X per error, but I still have the extra noise (lines starting with '+'). 我现在每个错误有一个红色X,但我仍然有额外的噪音(以'+'开头的行)。
In a build with Visual Studio 2013, I have tested with these two approaches and worked: 在使用Visual Studio 2013的构建中,我已经使用这两种方法进行了测试并且工作:
[Console]::Error.WriteLine("An error occurred.")
$host.ui.WriteErrorLine("Other way to show an error.")
Hope that helps. 希望有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.