Hi Guys - Looking at the documentation for variables, it says:
Complex syntax
Additional conditional statements are supported in Octopus 3.5 and onwards, including == and !=.
Using complex syntax you can have expressions like #{if Octopus.Environment.Name == “Production”}…#{/if} and #{if Octopus.Environment.Name != “Production”}…#{/if}
We have used this syntax for a few of our variables, but we would like to be able to use this to set some of our default (ie unscoped) variable values basing them on other variable values, and would like to know if ‘else’ is supported in this complex syntax? For example:
#{if Octopus.Channel.Name == “Release Branch”}4#{else}5#{/if}
At the moment for simple ones we have to do this:
#{if Octopus.Channel.Name == “Release Branch”}4#{/if}#{if Octopus.Channel.Name != “Release Branch”}5#{/if}
We currently have a requirement to set this variable to one value for two of our channels (which already requires using nested ‘if’ branches), and another value for every other channel, so I’m trying to figure out the best way to do this. If you have any other suggestions I am open to them, but I think that adding ‘else’ to the ‘if’ syntax would be a great addition if it’s not already there.
What happens if you have multiple default (unscoped) entries, like this:
variablename = 4
variablename = #{if Octopus.Channel.Name == “Release Branch”}5#{/if}
variablename = #{if Octopus.Channel.Name == “Another Branch”}5#{/if}
How would these be evaluated at deployment time? Do they all get tested (if so in what order?), or would it randomly pick up one of them? From the testing I’ve done, it always seems to just get the value of ‘4’, regardless of the Octopus.Channel.Name value.
Cheers, Simon.