How does variable resolution work with Library Sets and Project

What are the rules for variable resolution when the same variable is defined in multiple places like Library set(s) and Project , which one is chosen (do you get a warning if multiple definitions exist?). Wonder both which gets chosen for deployment, and which value gets extracted through the reference syntax #{MyVariable}, when multiple values are available.

I heard that the precedence rules should be: First pick Project defined and then pick Library Defined in the precedence order on the library import? However - that leads to the strange fact that LibraryX might extract a (multiply-defined) variableA from LibraryY, instead of the more natural LibraryX. (just because LibraryY happened to be imported with a higher precedence thatn LibraryX )

Hi @victor.cassel,

Thanks for getting in touch!

We aim to select variable values based on the scoping of those values. The more specific the scope, the higher up the list it goes in order of preference. This is detailed fully here: Variables - Octopus Deploy

So, there are situations when a Project level variable will be chosen before a Library set variable, and vice versa, It all depends on the scoping.

If a variable is defined in multiple places with the exact same scoping, then it is going to be unpredictable which value is chosen. We would always encourage users to avoid accidentally duplicating variables by applying specific naming conventions e.g. proj.connectionString or library.connectionString

Regards,
Paul

Thanks, good too know!

I think however that a predictable order would be better than an undetermined for those corner cases.

Best regards,
Victor

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