5

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:

errors

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.
  2. I would like to remove all the noise, i.e. 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?

I saw the function Write-VstsTaskError but unfortunately it can only be called from a VSTS task. It cannot be called from my script.

3 Answers 3

9

The recommended way to do this is using VSO logging commands as discussed in the GitHub issue below.

For example:

Write-Host "##vso[task.logissue type=warning;]Test warning"
Write-Host "##vso[task.logissue type=error;]Test error"
Sign up to request clarification or add additional context in comments.

3 Comments

It is important to note that adding errors through logging commands does not mark the build step as failed. One must therefore throw an exception (or log on stderr) when it logged at least one error through logging commands.
Good point regarding failing the build step. I've corrected a typo in the first URL now.
That is what i need, but using TFS 2013. Is there any way to achieve it with 2013?
1

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 '+').

Comments

0

In a build with Visual Studio 2013, I have tested with these two approaches and worked:

[Console]::Error.WriteLine("An error occurred.")

$host.ui.WriteErrorLine("Other way to show an error.")

Hope that helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.