How to use Comparison filters in conditional statement

Dear support,

I am struggling in using Comparison filters in conditional statement.
If I do:

#{if #{Octopus.Deployment.Tenant.Tags | Contains "Mymodules/moduleA"}}
    <logger name="*" minlevel="Info" writeTo="moduleA" />
#{/if}

then it is processed as

#{if true}
    <logger name="*" minlevel="Info" writeTo="moduleA" />
#{/if}

while I expect the following:

<logger name="*" minlevel="Info" writeTo="moduleA" />

I tried alternative versions of that with no success.

Could you please give me examples of Conditional filters combined with the #{if} statment ?

I found any of them in documentation.

Regards. Pierpaolo

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

#{if #{Octopus.Deployment.Tenant.Tags | Contains "Mymodules/moduleA"}}
    <logger name="*" minlevel="Info" writeTo="moduleA" />
#{/if}

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?

Regards,

Shawn

Hello Shawn, thanks for your reply.

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:

<logger name="*" minlevel="Info" writeTo="moduleA" />

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 true}
    <logger name="*" minlevel="Info" writeTo="moduleA" />
#{/if}

If Octopus.Deployment.Tenant.Tags string does not contain “Mymodules/moduleA” then my configuration file contains the following string after Octopus variable substitution

#{if false}
    <logger name="*" minlevel="Info" writeTo="moduleA" />
#{/if}

Hope I clarified somehow

Regards

Pierpaolo

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?

Hi Pierpaolo,

I’ll jump in here for Shawn for the time being. :slight_smile:

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:

And in my text file I updated the if to:

#{if conditional}
    <logger name="*" minlevel="Info" writeTo="module" />
#{/if}

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.

I hope that helps, and let me know how you go.

Best regards,

Kenny

Thanks Shawn, Kenny,

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.

Have a nice day

Pierpaolo

Thanks goes to Kenny on this one, he was able to demonstrate to me what it was you were encountering. Thanks Kenny!!

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