We’re running an inline powershell script step with a script like this:
./terraform.exe plan
Because of an issue with our Terraform state, that command is failing. But when it fails I don’t see the command output in Octopus’s logs:
10:26:49 Error | NotSpecified:
10:26:49 Error | At D:\Octopus\Work\20200401142641-219175-22221\Script.ps1:28 char:1
10:26:49 Error | + ./terraform.exe plan
10:26:49 Error | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10:26:49 Error | at <ScriptBlock>, D:\Octopus\Work\20200401142641-219175-22221\Script.ps1: line 28
10:26:49 Error | at <ScriptBlock>, D:\Octopus\Work\20200401142641-219175-22221\Bootstrap.Script.ps1: line 2402
10:26:49 Error | at <ScriptBlock>, <No file>: line 1
10:26:49 Error | at <ScriptBlock>, <No file>: line 1
10:26:50 Verbose | Process C:\Windows\system32\WindowsPowershell\v1.0\PowerShell.exe in D:\Octopus\Work\20200401142641-219175-22221 exited with code 1
10:26:50 Verbose | Updating manifest with output variables
10:26:50 Verbose | Updating manifest with action evaluated variables
10:26:50 Fatal | The remote script failed with exit code 1
10:26:50 Fatal | The action Terraform plan on the Octopus Server failed
If I RDP to the worker and run the same command I get much more useful output:
Error loading state: state snapshot was created by Terraform v0.12.23, which is newer than current v0.12.21; upgrade to Terraform v0.12.23 or greater to work with this state
If I manually run the command with outputs redirected I see that the message was sent to stderr:
./terraform.exe plan 2>stderr >stdout 3>stdwarn
# stdout contains normal output
# stderr contains the error message about state snapshot
# stdwarn is empty, as expected
My worker is running .net 4.8:
(Get-ItemProperty "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full").Version
4.8.03761
So Octopus is terminating the script immediately when the error occurs, which is fine, but it doesn’t seem to capture the error output. How can I fix that?