Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress powershell output messages

I have a TFS 2013 Update 2 buildserver. When I build a project, I checkout some files, alter some things and check it in again. This works great. The only problem is when someone has checkout one of those files, the buildserver will see that as an error and the build will be partially succeeded. Actually it is just an information message but the build sees it as an error. How can I suppress those messages?

I have the following Powershell command:

Add-TfsPendingChange -Edit -Item $PathToFolderToCheckout -Recurse

The command is from the TFS 2013 Power Tools.

I tried the following but it doesn't work:

  • Add -ErrorAction with Igonore and SilentlyContinue
  • Add -Out-Null
  • Try and empty Catch

The message that is thrown for each file is: Path to file: opened for edit in Workspace;Ralph Jansen

Thanks

like image 668
LockTar Avatar asked Nov 01 '22 16:11

LockTar


2 Answers

I believe it needs to be in the standard output stream to be sent to null. Try this:

$Null = Add-TfsPendingChange -Edit -Item $PathToFolderToCheckout -Recurse *>&1 

*>&1 redirects all output to standard output and $null is a reserved variable for this purpose. It is more efficient than piping to out-null.

Another alternative could be to set the action preference for errors. I've seen before where cmdlets don't seem to acknowledge the -ErrorAction common parameter.

$ErrorActionPreference = 'SilentlyContinue'
Add-TfsPendingChange -Edit -Item $PathToFolderToCheckout -Recurse
$ErrorActionPreference = 'Continue'
like image 76
Noah Sparks Avatar answered Nov 18 '22 22:11

Noah Sparks


After some efforts, I successfully get it for our Tfs builds! \o/

You have to end the command line with *>&1 | out-null

For exemple:

Add-TfsPendingChange -Edit -Item $PathToFolderToCheckout -Recurse *>&1 | out-null

The side effect is that all the messages that cause the errors are lost.

like image 40
Philippe Avatar answered Nov 18 '22 21:11

Philippe