Previous step name in custom step template does not work in

I have a step template in Python3 with parameter of previous_step_name
prev_step_name = get_octopusvariable(“previous_step_name”)
get_octopusvariable(“Octopus.Action[#{prev_step_name}].Output.ExecutionId”)

get_octopusvariable
Error
return octopusvariables[key]
Error
KeyError: ‘Octopus.Action[#{prev_step_name}].Output.ExecutionId’
Fatal
The remote script failed with exit code 1

Hi Tony,

Thanks for getting in touch, and welcome!

I suspect you’re hitting a syntax issue here. Octopus treats everything in quotes as a string, and the standard variable substitution syntax (i.e. #{var}) won’t substitute a variable value that was created in the Python script into the string. The syntax that I got working in my local instance is as follows ({} denotes where to substitute):

prev_step_name = get_octopusvariable("previous_step_name")
get_octopusvariable("Octopus.Action[{}].Output.ExecutionId".format(prev_step_name))

Where previous_step_name is a parameter in my step template that holds the value of the step name that created the ExecutionId output variable.

I hope that helps! Let me know if we can assist with anything else moving forward. :slight_smile:

Best regards,

Kenny

1 Like

It works now! Thank you, Kenneth!

Hi Tony,

You’re very welcome! Glad that helped. :slight_smile:

Don’t hesitate to reach out if you have any questions or concerns in the future!

Best regards,

Kenny

I just found out below works too:
execution_id = “#{Octopus.Action[#{previous_step_name}].Output.ExecutionId}”

What are the difference between using get_octopusvariable and #{}? #{} returns a variable, but get_octopusvariable returns a string?

Hi Tony,

Thanks for following up. #{previous_step_name} is a parameter in the step template, and can be substituted in with that standard syntax used by Octopus and will match on name. The prev_step_name is a variable created in the Python script, and substituting the value of it into the string had to use the specific Python syntax.

I hope that helps!

Best regards,

Kenny

My question was actually on get_octopusvariable vs #{}. What is the difference? #{} returns a variable, but get_octopusvariable returns a string?

BTW: do we have a reference wiki about how to use the variables?

Thank you, Kenny

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