Run condition variables, two conditions

(gvrsv) #1

Hi,
We are trying to use new feature ‘Run condition variables’.
Is there a way to evaluate the whole expression as true, if it consists of two conditions?
something like
#{if Octopus.Environment.Name == “Production”} AND #{if VariableName == “True”}
or
#{if Octopus.Environment.Name == “Production”} && #{if VariableName == “True”}

Thank you!

Variable Conditionals and using OR statement
(Dalmiro Grañas) #2

Hi,

Thanks for reaching out! At the moment that is not possible. Feel free to add a uservoice suggestion for it though: http://octopusdeploy.uservoice.com/ . I would go with a subject along the lines of Allow Variable run condition to support many variables and not just boolean values and then explain it a bit more with examples in the description.

For the time being if you want something to only run when in Production and if the variable VariableName is True, you’re gonna have to scope the variable to the Production environment and set the Run Condition to watch for that variable.

Regards,
Dalmiro

(chris.camburn) #3

@Dalmiro (and anyone needing to do multi-variable conditionals)

I believe there is a way to do this currently. I did some decent testing, as I needed to have a prompted variable to run a step, but I ALSO needed the step to only run if all previous steps were successful.

What I did (based on Octostache documentation) was to use the following:

#{unless Octopus.Deployment.Error}#{PromptedVariable}#{/unless}

This allows me to only run on success and with PromptedVariable == True.

In a similar fashion, I tested using multiple prompted variables, such as this:

#{if PromptedVar}#{AnotherVar}#{/if}

And it also worked as expected. Perhaps this is something that should be added to the documentation, as it is INCREDIBLY useful to run conditionals combined with only on success / failure of previous steps.

(Dalmiro Grañas) #4

Hi Chris,

You are 100% right on this one. It was my bad for not consulting this one with the team before answering.

The syntax #{if Var1}#{Var2}#{/if} totally works to set the step condition to use 2 variables. We’ll be adding this to our documentation in shortly.

Kudos and thanks for stepping in!

Dalmiro

(Alex) #5

Hi, guys.

How i can see #{if Var1}#{Var2}#{/if} variant not working. You need to put another closing /if tag.

#{if TrueORNot == “Y”}#{if GoOrNot == “Y”}True#{/if}#{/if}

Something like that. In bot variables need to be Y to deploy step.

(chris.camburn) #6

Alex,

In my testing, using #{if Variable1}#{Variable2}#{/if} has been working. As long as Variable1 and Variable2 are both ‘true’ then it runs.

Keep in mind, if you’re setting the variables to ‘Y’ then you will need what you have written. If you set them to ‘true’ or ‘false’, there is no need for the == in the evaluation, you can just use #{Variable}.

(Alex) #7

Hey, Chris.

Trick is about variables which are not true or false. They were needed to be everything what you want Y\N\Number\SomethingElse.

Thanks.

(system) closed #9