Access dynamic step variable from PowerShell

Hi,

I am trying to access a variable from a previous step defined as a “Previous Deployment Step name” parameter from PowerShell.

Regular syntax for static step name is:

$PrevStepParam = $OctopusParameters["Octopus.Action[PrevStepName].Output.Param"]

However what would the syntax look like for dynamic PrevStepName?

I would need something like the below, but cannot figure out the right syntax:

$PrevStepParam = $OctopusParameters["Octopus.Action[$OctopusParameters['PrevStepName']].Output.Param"]

Thank you in advance.

Hi @it_group,

Thanks for getting in touch! Unfortunately I don’t think we’d have a great answer on how to achieve this, since the previous step name isn’t stored in any system variable, and output variables won’t work since you have to specify the step name that created the output variable. Currently I think the only option (which certainly isn’t nice) would be to write the relevant step name to a text file which you could then read out when needed.

I’d be happy to try to think of any potential out of the box ideas. Can you elaborate a bit on what you’re trying to achieve and what you’re requiring?

I hope this helps, and I look forward to hearing back!

Best regards,

Kenny

Hi Kenny,

Thank you for you reply.

For the record I ended up implementing your suggestion, i.e. storing the previous step name into a text file. This way I could accomplish what I wanted.

Thank you for your help.

Hi @it_group,

You’re very welcome! Great to hear that worked, and thanks for letting me know the outcome. Don’t hesitate to reach out if you have any questions or concerns in the future. :slight_smile:

Best regards,

Kenny