简体   繁体   English

添加错误以从VSTS中运行的PowerShell脚本构建摘要

[英]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: 我正在寻找的改进是:

  1. I would like to have one red X per error. 我想每个错误有一个红色X.
  2. I would like to remove all the noise, ie get rid of the lines starting with '+' 我想删除所有的噪音,即摆脱以'+'开头的行

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问题中所述。

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.

相关问题 Powershell / VSTS构建-存储凭据独立/与用户运行脚本无关 - Powershell / VSTS Build - Store Credentials Independent/ Agnostic of User Running Script 在VSTS部署组上运行PowerShell脚本 - Running PowerShell script on VSTS deployment group 如何在作为VSTS构建/发布的一部分运行的PowerShell脚本中检索变量? - How do I retrieve variables in a PowerShell script running as part of a VSTS build/release? 需要在 powershell 脚本末尾创建错误摘要 - Need to create a summary of errors at the end of a powershell script 在VSTS中使用Powershell运行Webpack - Running webpack with powershell in VSTS VSTS:将构建/发布变量传递到 Powershell 脚本任务中 - VSTS: Pass build/release variables into Powershell script task VSTS Build Definition中的Powershell脚本不更新AssemblyVersion.cs - Powershell script in VSTS Build Definition not updating AssemblyVersion.cs 在vsts中运行的Powershell脚本不会识别环境变量 - Powershell script running in vsts release not recognizing environment variables 从Powershell调用vcvarsall.bat后运行构建脚本 - Running a build script after calling vcvarsall.bat from powershell 从TeamCity构建中运行PackageWeb Powershell脚本时出错 - Error running PackageWeb Powershell script from TeamCity build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM