Get variable value for e-mail from previous step in run book

I see a few items about getting variables from previous steps in a project but can’t get it working in a RunBook. Is there a different way to go this in a run book?

I have a project variable set on the project scoped to the runbook process named “EndPoints”

From Powershell Script in first step
Set-OctopusVariable -name “EndPoints” -value $global:EndPoints

From Body section in next step
#{Octopus.Action[ADCleanupScript].Output[EndPoints].WorkItems}

Hey @CHR,

Thanks for reaching out on our community forum. You’ve set a variable in step one and are trying to access it in step 2. The issue is that you’ve defined the variable as ‘EndPoints’ in step 1, then in step two, based on your structure, you’re trying to access the var WorkItems on a deployment target called ‘EndPoints’.

That structure is for referencing a var set on a deployment target, like if a test passed or failed. More info on that is shown here.

If you want to reference your EndPoints variable in step 2, you’d want to use this: #{Octopus.Action[ADCleanupScript].Output.EndPoints}

I wrote a quick setup you can test if you’d like:

Step 1 Script Body:

write-host 'evaluating var req'
$MyVar = 'awsaddress'
Set-OctopusVariable -name "EndPoints" -value $MyVar

Step 2 Script Body:

write-host 'printing value of var set in prev step'
write-host #{Octopus.Action[ADCleanupScript].Output.EndPoints}

If you run those two steps it will print the value of the EndPoints Variable:

More info on output variables can be found here, the examples listed should help you get the info you need in that next step.

Let me know if you have any questions.

Best,
Brent

Thank you. That worked!

2 Likes

Awesome! Let us know if anything else comes up.

Happy deployments!

Brent

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