Suppressing Errors in Custom PowerShell Scripts

(rehansaeed) #1

I have a few releases which say “The task completed successfully but errors were reported in the log” because I have some retry logic in my PowerShell which can sometimes error but eventually succeeds.

How can I stop that PowerShell code from displaying an error in Octopus Deploys logs? Please note that I am calling an external executable from my PowerShell and not a cmdlet. I have tried using a try catch in my PowerShell script:

try
{
    someProcess --argument;
}
catch
{
}

I have also tried redirecting standard error output like so:

someProcess --argument  2>&1 | out-null;
(Michael Richardson) #2

Hi,

I would have thought redirecting standard-error, exactly as you tried, would have worked. But you’re correct, it doesn’t. I’m still not exactly sure why…

The only way I could find to work around it, was to add an indirection and invoke it via cmd.exe. i.e:

&  cmd /c "someProcess --argument 2>&1" | out-null

Please let me know if this helps?

Regards,
Michael

(rehansaeed) #3

Can I raise a bug report somewhere?

(Michael Richardson) #4

This is not an issue specific to Octopus Deploy.
For example, have a look at this StackOverflow answer.

I think it’s just a quirk with the way PowerShell handles output and error streams. It seems they behave differently depending on the host (Console vs ISE vs PowerShell.exe).

A bit painful though, I know.

Docker steps are failing with newer powershell
(system) closed #6