Variable substitution in variables

modelling

(SKB Kontur) #1

Hi!

I have a variable, that must be true or false, based on deployment step name. I’m trying to use variable substitution syntax for this, but have no success, for example:
variable #{TestRequestBody} has value

{
  "IsLegacyReplica": #{if Octopus.Action.StepName == "Legacy"}true#{/if}
}

In a test script i just write out this variable. And Octopus don’t substitute anything and just write out variable with placeholders.

Also, can be this check case insensitive? And can i use “else” statement?

Kind Regards,
Alexander Yuzhanin


(Kenneth Bates) #3

Hi Alexander,

Thanks for getting in touch! Unfortunately I’m not sure I fully understand your environment and requirements as well as I’d like to. Are you using the JSON configuration variables feature and wanting to substitute a value (true/false) into your JSON file based on the step?

If so, I think it’d be easier to define the variable name as IsLegacyReplica with a value of true which you can scope to the Legacy step. You can then create another variable with the same name, leave it unscoped and with a value of false. The previously linked doc page outlines the syntax to substitute JSON values with a few different scenarios.

As of 2018.3.0, we’ve also added support for else statements in Octostache (you can view the issue here). So something like this is now supported: #{if Octopus.Action.StepName == "Legacy"}true#{else}false#{/if}, which could be the value of the IsLegacyReplica variable, which would avoid needing multiple scoped values.

Please let me know if I’m misunderstanding anything! I’ll be happy to reassess with more info. :slight_smile:

Kind regards,

Kenny


(SKB Kontur) #4

Hi, Kenneth!

I’m not using json configuration variables. I want to use this syntax to form ordinary variable, that will be used in deployment scripts (as a request body for invoke-webrequest, for example). I can insert in variable some other placeholder and replace it with custom deployment script, but it be great if octopus can do it itself.

Kind Regards,
Alexander Yuzhanin


(SKB Kontur) #5

Hi, Kenneth! Maybe screenshot of variable will help to understand the problem i’m trying to solve.

Kind Regards,
Alexander Yuzhanin


(SKB Kontur) #6

Hi, Kenneth!

I found a syntax error in my variable and now it works for steps with name “Legacy”
Is there possibility for some string operations? I want to use expression like “if step name contains ‘Legacy’ ToLower …”, but cant find examples in the octostache code.

Kind Regards,
Alexander Yuzhanin


(Kenneth Bates) #7

Hi Alexander,

Thanks for following up! That’s great to hear you found what the issue was! Unfortunately there’s no support for contains or anything similar to it. Only == and != are supported.

Theoretically (I haven’t had a chance to test this) you could do something similar with something like #{if Octopus.Action.StepName == "Legacy"}#{Variable | ToLower}#{else}#{Variable}#{/if}, but that may require you to define many different possible step names. Is something like that what you’re looking to achieve?

I hope this helps! Let me know what you think or if you have any further questions. :slight_smile:

Best regards,

Kenny