Will variable filters work directly in Variables/ Project Variables?

Support Team,

Is it possible to use variable filters with in the variables? I want to do like, for some channels the define variable values should be different, so looking to get the Replace function work with in the variables/ project variables but it is not working. Mentioned below what works and what not, so can you please help me here?

Not Working
#{Tenant.PhysicalDataFileName | Replace “.mdf” “Base.mdf”}
#{Tenant.SQLDatabase | Substring 8 7}
#{Octopus.Project.Name | Trim}

Works
#{Tenant.PhysicalDataFileName | ToLower}
#{Tenant.PhysicalLogFileName | ToUpper}
#{Tenant.TestDate | Format Date MMM}

Regards,
P.Prabhakar

Hi @pnp.prabhakar,

Thanks for getting in touch! Great question, and I did a bit of testing locally to have a direct look at this behavior. However, testing with the | Trim filter like you mentioned as not working, that looks to work as I expected in my testing. This was with a variable, named say Whitespace with whitespace characters before and after the value, then defining another variable named WhitespaceTrim with a value of #{Whitespace | Trim}. Writing WhitespaceTrim in my step correctly trims off those whitespace characters.

I’m not positive I’m testing this in the same way as you are, though, so I was hoping you could detail how these variables are being defined and called in your script? Also, which version of Octopus are you currently running? I tested this locally in 2021.3.4482, so it might be the case that you’re hitting a previously and since-fixed bug?

I look forward to hearing back!

Best regards,

Kenny



Task Log Output
Octopus Version
Thanks @Kenneth_Bates for giving a good start of the day to me through your fast reply.

The version of Octopus that I am using is 2018.5.1 and I am trying to achieve this Replace functionality with in the variables itself, as my requirement is to scope it based on the channel, meaning the values should be different for the said variable based on the Channel.

So, all I need is to get the Replace function working in the variable AReplace which refers another variable as #{Tenant.PhysicalDataFileName | Replace “.mdf” “Base.mdf”}

In the event of trying to do this only, I checked few other filters and found that only ToLower, ToUpper and Format works, but Replace, Substring and Trim are not working. So, can you please let me know, if I am missing any settings or something, if I open the variable editor and try to change it from Plain Text to something also it is not working. I have attached the screenshots of the variables, it’s preview and the output.

Hi @pnp.prabhakar,

You’re very welcome, thanks for the update and additional details! I ran through a quick test and can confirm this behavior in the case of the AReplace with value #{Tenant.PhysicalDataFileName | Replace .mdf Base.mdf}. To fix it I had to enclose both Replace arguments within quotes, so #{Tenant.PhysicalDataFileName | Replace ".mdf" "Base.mdf"}.

| Substring worked as expected, as well as the previously mentioned | Trim, and filtered the values of the variables in which these are bound to correctly. Is it possible the expected values of these variables are not applicable to your variable preview criteria? E.g. did you select the channel in the variable preview in which these variables are scoped to?

I had a look at issues and can’t spot any closed since 2018.5.1 that seems aligned with this issue, but there is still a chance this was a bug that was fixed in conjunction with some other fix.

I look forward to hearing back!

Best regards,

Kenny

@Kenneth_Bates

I have already included double quotes, which can be seen in the 1st screenshot that I attached, so none of these three Replace, Substring and Trim works for me, though I ultimately want only Replace to get working. And no, the preview criteria is correct, in fact I just tried without any scope/criteria in a new project and attaching the screenshots for your reference.

So, are there any chances that, I might be missing some settings/ configuration in Octopus that has to be enabled? Let me see also if anybody else has a higher version where we will try this.


Hi @pnp.prabhakar,

Thank you for following up and confirming that. It certainly looks like how you have these variables defined should be applying these filters as we both expect in the preview (no issues with scoping or syntax or anything else). Here’s my setup mimicking your details in my local instance (2021.3.4482).

Variable Page*:

Variable Preview Page:

I’m wondering if it’s an issue only within the preview itself - if you have had a chance to deploy a release that contains these variable definitions, do these variables evaluate correctly?

Best regards,

Kenny

Hi @Kenneth_Bates

Again, thank you for the quick turnaround, looks like it is version compatibility issue, I checked with someone else who had 2018.5.1, there it didn’t work but with another person who is in 2020.x it works, which makes me conclude that it is not supported in older versions. So, I will go with a workaround for now until we upgrade to a higher version.

Appreciate your support on this!

Regards,
P.Prabhakar

Hi,

Not a problem at all, thanks for the follow up and info! Don’t hesitate to reach out anytime with any questions or concerns. :slight_smile:

Best regards,

Kenny