In VSTS, I am using a PowerShell task to run one of my script. 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:
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?
I saw the function Write-VstsTaskError but unfortunately it can only be called from a VSTS task. It cannot be called from my script.
To write a non-terminating error, enter an error message string, an ErrorRecord object, or an Exception object. Use the other parameters of Write-Error to populate the error record. Non-terminating errors write an error to the error stream, but they do not stop command processing.
In that case, use Stop for the ErrorAction . When you run a command using the Stop value, PowerShell treats any errors returned as terminating and acts accordingly. You can control non-terminating and terminating errors globally using the $ErrorActionPreference variable.
If there are special commands you want to ignore you can use -erroraction 'silentlycontinue' which will basically ignore all error messages generated by that command. You can also use the Ignore value (in PowerShell 3+): Unlike SilentlyContinue, Ignore does not add the error message to the $Error automatic variable.
The recommended way to do this is using VSO logging commands as discussed in the GitHub issue below.
Is it possible to raise and display build warnings from build steps using TFS 2015?
Logging Commands
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. The VSTS build displays a red X for each entry in stderr that is seperated by an entry on 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 '+').
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With