Is there any way to programmatically get a list of step names?

I’m trying to run prerequisite checks before my deployment. I have a child step for each check and if an exception occurs in a step, I am writing the exception message to an output variable for that step.

I then want to create a report to see which prerequisite checks failed. I’m currently doing this by hard coding step names and running through each one to check if an output variable has been set for that step.

Clearly hard coding is not a great way to accomplish this. Is there a way to do this programmatically?

Hi Jack,

I think I understand what you are looking to achieve.

One option is to use the built-in indexing capability of Octopus Output-Variables. You can set your errors as, for example:
Set-OctopusVariable -name "Error" -value "Step A failed"

As detailed in the output-variables documentation, the script above will automatically set a number of output-variables, including:
Octopus.Action[MyStep].Output.Error

Assuming you do this in each of your steps, in your report step, you can run a script that looks something like:

#{each step in Octopus.Action}
   #{if step.Output.Error}
      Write-Host "#{step.Output.Error}"
   #{/if}
#{/each}

This will iterate over each step (see the documentation for repetition and conditionals in Octopus variable syntax), and if the step has an Error variable defined, it will print it. Obviously you can replace the Write-Host with your own functionality.

I hope that helps.

Regards,
Michael

Thanks a lot Michael, that’s just what I was looking for.

You’re most welcome.

Happy Deployments!