Logs from just a single step?

Is it possible to pull logging for just a single step?

I see where we can pull the logging for an entire Task via the API using something like:
Invoke-WebRequest -Uri “https://<YourServerHere>/api/Spaces-#/tasks/ServerTasks-#####/raw”

Was wondering if you can just get the logging from a single step? Example being when a step logs a error, we’d like to pull just those logs to facilitate troubleshooting.

Thanks.

Hi @jamie.sidoti

The logs returned from the API are in an unstructured data format. As such, you can’t choose a specific step (the logs aren’t stored by step).

You can retrieve the full logs using the Server Tasks details endpoint e.g.

https://<YourServerHere>/api/Spaces-#/tasks/ServerTasks-#####/details

This returns data in a format similar to this (this is JSON data formatted in my browser):

The JSON equivalent, just for completeness:

You’d have to look for the step name (step numbers are added to the log by Octopus) as a like/wildcard search and then look for the errors pertaining to just that step.

I did write a script that does something similar to what you’re after potentially here

It’s written in C#, using the Octopus.Client library and given the following deployment:

It would return you the logs like so:

Fatal: The deployment failed because one or more steps failed. Please see the deployment log for details.
Fatal: The step failed: Activity SQL - Execute Script on a Worker failed with error 'The remote script failed with exit code 1'.
Fatal: The remote script failed with exit code 1
Fatal: The action SQL - Execute Script on a Worker failed
Error: NotSpecified: Exception calling "ExecuteNonQuery" with "0" argument(s): "Invalid column name 'isSummaryFilter'."
Error: At C:\Octopus\Work\20220707083538-104807-11\Script.ps1:28 char:13
Error: +             $command.ExecuteNonQuery() | Out-Null
Error: +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: at <ScriptBlock>, C:\Octopus\Work\20220707083538-104807-11\Script.ps1: line 28
Error: at Execute-SqlQuery, C:\Octopus\Work\20220707083538-104807-11\Script.ps1: line 22
Error: at <ScriptBlock>, C:\Octopus\Work\20220707083538-104807-11\Script.ps1: line 50
Error: at <ScriptBlock>, <No file>: line 1
Error: at <ScriptBlock>, C:\Octopus\Work\20220707083538-104807-11\Octopus.FunctionAppenderContext.ps1: line 211
Error: at <ScriptBlock>, C:\Octopus\Work\20220707083538-104807-11\Bootstrap.Octopus.FunctionAppenderContext.ps1: line 1587
Error: at <ScriptBlock>, <No file>: line 1
Error: at <ScriptBlock>, <No file>: line 1
Error: The remote script failed with exit code 1

I hope that helps!

Best