Conditional statements in variables

Hi Guys,

I was wondering if there is a way to use the conditional statement, from the extended substitution syntax, within the value of a variable?

One of the sites we develop is editable or read only at certain times of the year and is controlled by changing settings in Web.configs and JSON files. At the moment these changes are applied manually and I would like move control of this to octopus. Initially my thinking is to control this using one variable as a Boolean and then use the conditional statements in the substitution syntax to change the value of the variables along the lines of this:

Variable     Value

settingA     #{if readOnly} value1 #{/if}  #{if !readOnly} value2 #{/if}
readOnly    True/False

Hi Chris,

Thanks for getting in touch! you can do this. I believe the best way would be to use the if & unless statements, I do not believe value & !value works with our substitution syntax. Though we do allow = & !=, I don’t think we need that here. I tested the following on my server and it worked great.

readOnly:

True/False

settingA:

#{if readOnly} Value1 #{/if} 
#{unless readOnly} Value2 #{/unless}

This is because our if & unless are already evaluated in Octopus as boolean, so there is no need for any explicit not equals.

Let me know if this helps or if you have any issues/further questions. :slight_smile:

Best regards,
Daniel

Ah, Cheers Daniel.
That works perfectly. Should have read the documentation more instead of skimming.

Hi Chris,

No worries! Feel free to get in touch at any time. :slight_smile:

Best regards,
Daniel