SharpeRAD / Cake.Powershell

Powershell addin for Cake
http://cakebuild.net
MIT License
83 stars 36 forks source link

Failure when running on TeamCity #19

Closed DixonDs closed 7 years ago

DixonDs commented 7 years ago

It works fine on my local env, but fails when I try to run it on TeamCity:

System.Management.Automation.CmdletInvocationException: The handle is invalid.
---> System.IO.IOException: The handle is invalid.

 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
 at System.Console.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
 at Cake.Powershell.CakePSHostRawUserInterface.get_BufferSize()
 at Microsoft.PowerShell.Commands.OutStringCommand.InstantiateLineOutputInterface()
 at Microsoft.PowerShell.Commands.OutStringCommand.BeginProcessing()
 at System.Management.Automation.Cmdlet.DoBeginProcessing()
 at System.Management.Automation.CommandProcessorBase.DoBegin()
 --- End of inner exception stack trace ---
 at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
 at Cake.Powershell.PowershellRunner.Invoke(String script, PowershellSettings settings)
 at Submission#0.<.ctor>b__16()
 at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass5_0.<Does>b__0(ICakeContext context)
 at Cake.Core.ActionTask.Execute(ICakeContext context)
 at Cake.Core.DefaultExecutionStrategy.Execute(CakeTask task, ICakeContext context)
 at Cake.Core.CakeEngine.ExecuteTask(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)

Quick Google search lead me to this SO link that could be relevant: http://stackoverflow.com/questions/327408/the-handle-is-invalid-when-running-net-console-via-java

SharpeRAD commented 7 years ago

Sorry I don't have access to a TeamCity server, please submit a PR for any required changes.

DixonDs commented 7 years ago

Ok, I will try to look into it and submit a PR if I get a chance. But from what I understand, it is not specific to TeamCity (I was just giving more context here), but rather to the fact that there is no normal console window available, but console output is redirected, so properties like Console.BufferWidth may fail.

perakerberg commented 7 years ago

I have the same issue when running on Jenkins. However, if I skip formatting output, it works.

So, PowershellSettings().SetFormatOutput().SetLogOutput(), fails with "The handle is invalid".

But, new PowershellSettings().SetLogOutput()works.

Maybe that helps with finding the problem. Thanks for the great work!

SharpeRAD commented 7 years ago

settings.OutputToAppConsole = false; When the environment doesn't support console outputting.