Greetings Pierpaolo, thanks for reaching out! I’m sorry to hear that you are having difficulties with the conditional statements. I’m having a little difficulty following, but what I think you’re saying is that you have
Which is always evaluating to True, is that correct? Another question is are you using this conditional statement in a variable value or as a Run Condition on a step?
I am using the conditional statement in a configuration file which is processed by variable substitution of octopus.
What I would like to achieve is the following:
if Octopus.Deployment.Tenant.Tags string contains “Mymodules/moduleA” then my configuration files processed by Octopus variable substitution must contain the folowing string:
And an empty string if Octopus.Deployment.Tenant.Tags string soes not contain “Mymodules/moduleA”
What I do obtain currently from Octopus variable substitution is the following:
If Octopus.Deployment.Tenant.Tags string contains “Mymodules/moduleA” then my configuration file contains the following string after Octopus variable substitution
If Octopus.Deployment.Tenant.Tags string does not contain “Mymodules/moduleA” then my configuration file contains the following string after Octopus variable substitution
Hey there Pierpaolo! Would you be open to a call? Your reply makes it look like true and false would result in the same value. I think I’m missing a connection that maybe can be better explained on a call. Would that work?
I’ve been able to reproduce this behavior you’re reporting, and my apologies for the confusion this unexpected outcome is causing. It looks like Octopus is correctly evaluating the truthiness of #{Octopus.Deployment.Tenant.Tags | Contains "Mymodules/moduleA"} and inserting the true or false value into your #{if} statement, but is not going one step further and evaluating that new #{if true}.... I found that unexpected, so I’m going to raise this question internally to see if it’s a bug, or there’s some reason I’m unaware of for this to work in this way.
In my playing around, I was able to work around this and get the desired outcome by creating a new project variable, placing the content #{Octopus.Deployment.Tenant.Tags | Contains "Mymodules/moduleA"} as its value, and modifying the #{if...} statement to check the truthiness of that new project variable. E.g. the project variable in my local test looks like this:
It doesn’t feel nice to have to workaround this in that way, but that might help? Alternatively, I imagine you could trigger substitution a second time on the same file so that it can evaluate that leftover #{if...}, but I haven’t given that a test myself. This option would likely include enabling this same feature on a subsequent script step and pointing it to this same directory\file.
Indeed, as you proposed I created an intermediate project variable.
I will look forward to see the final solution in order to use directly the comparison filters within the #{if} statement.