Powershell error output not shown #26951
-
I’m running a Powershell script in a GHA workflow (windows-latest runner) and the output when an error occurs doesn’t seem to show the reason for the failure. All it shows is “##[error]Process completed with exit code 1.” This is problematic: the script appears to crash at this point and I can’t get output to show. I’ve also tried to output the failure using try/catch: this stops the script failing, but output statements in the catch block aren’t shown. I have direct EXE invocations at other points and they show errors; it’s just powershell script invocation that dies without a trace. This makes it very difficult to understand why a script is failing. Adding step debugging produces more output about invocation, but doesn’t give any extra information about the issue. For example, a script:
with a YAML:
Results in the following output:
In this case, the first exception message is printed out BUT the second isn’t. In my case, where I’m using signtool, or Get-PfxCertificate, it just crashes entirely. Losing this kind of context means that I’m stumped why my script isn’t working: I can make it work on a number of local machines and environments, but not the GHA runner. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Thank you for reporting this issue. I have asked help from engineering team , when they give me any response I will update here soon. |
Beta Was this translation helpful? Give feedback.
-
Thanks for forwarding this on! I’ve done some further investigation, and some further investigation. As far as I can tell, if script processing results in an exception being thrown, then:
This is understandable, but the lack of error output creates confusion and becomes difficult to debug. It is possible to work around this limitation by specifying a custom shell:
The value for This custom shell (see doco) trys to follow the behaviour of the default Therefore, if there is any script parsing error, or if there is a runtime error with the script, some details will be printed to the output to aid debugging. It would be great if the built in shell would pick up and improve this behaviour: it would be a great UX improvement when trying to get a pipeline working! |
Beta Was this translation helpful? Give feedback.
-
Note BTW that the doubled starting and closing braces are necessary as this string is passed to C#'s String.Format method, which requires the braces be doubled to escape them. The doubled quotes are for command line escaping. |
Beta Was this translation helpful? Give feedback.
-
Thank you for sharing your workaround here. I appreciate your contribution. I will report your feedback to product team. |
Beta Was this translation helpful? Give feedback.
Thanks for forwarding this on!
I’ve done some further investigation, and some further investigation.
As far as I can tell, if script processing results in an exception being thrown, then:
This is understandable, but the lack of error output creates confusion and becomes difficult to debug.
It is possible to work around this limitation by specifying a custom shell: