Correct way to reference step template parameters

I have a custom step template which contains two user-defined parameters, IP Address (with the underlying variable named #{IP}) and Host Name (with the underlying variable named #{HostName}). I reference these in the step PowerShell script using $OctopusParameters[‘IP’] and $OctopusParameters[‘HostName’]. I can populate these variables successfully using the form fields when adding the step template to a project. The problem I’m having is that in one of my projects I also have a custom variable named HostName which is overriding the value typed into the form field. Is this correct behaviour? Should I use more obscure variable names in my step templates to avoid clashes, or is there a safer way to reference variables typed into step template input fields other than using $OctopusParameters[‘SomeVar’]?

Hi,

Thanks for reaching out. You’re gonna have to change the variable names, yeah. This is the expected behavior, as both variables (step template ones and project ones) are basically Octopus variables.

Regards,

Dalmiro

Is there any guidance on naming parameters for use in step templates? - especially those submitted to the Octopus Library. This behaviour isn’t widely publicised and strikes me as a bit risky.

Hi Rob,

We don’t have a guide for variable naming. Pretty much the only gotcha is not to name them the same as a project variable. I believe we could improve this a bit, maybe displaying a warning that tells the user they have duplicate variable naming and that the Project-level variable will prevail in this case. I’ve logged a github issue to discuss this with the team.

I would recommend you to add a prefix to all variables that come from a parameter on the step template, like the letter “p” ($pUsername, $pPassword).

Thanks,

Dalmiro