Using an output variable in runbook step

Hi,
Is there a way to save a variable from a Powershell script so I can use it in another step in my runbook?
So when I run my Powershell script I want to save an output variable to use in the next step of my runbook.
Is this possible?

Kind Regards,
Micheal Power

Hi Mike,

Thanks for reaching out. We’ve got some documentation talking about your options.

What you would be looking to do, is set your variable using this command:

Set-OctopusVariable -name "MyVariableName" -value "This is a variable"

and reference your variable in a later step, using this command:

Write-host $OctopusParameters["Octopus.Action[Set Octopus Variable].Output.MyVariableName"]

I will quickly point out the most common mistake that people make when using this syntax (even after reading through the documentation thoroughly). When you are referencing your variable, the part within the inner most square brackets [Set Octopus Variable] is the step name where you set the variable originally and it doesn’t require quotes.

I hope this helps.

Regards,

Dane

Hi @dane.falvo,
Thanks for the feedback.
I forgot to mention that the Powershell script will be run inside a package and not run in the Inline source code option in my runbook.
Is it possible to save a variable from the script when run inside a package and use it in the next step of the runbook?

Kind Regards,
Micheal Power

Hi @mikepower79,

Thank you for getting back to us.

This should work for scripts that are both inline and contained within a package as both are bootstrapped with calamari.

If you have any additional questions or run into any trouble once you get it set up, please let us know.

Best Regards,
Donny

Hi @donny.bell,

That’s great, thanks for the feedback.

Kind Regards,
Micheal Power

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.