Variable Substitution

Hi,

I am trialing out OD to show how it could work in our environment. Right now, I am just trying to deploy a single piece (a windows service that connects to and SMTP server and a database). We are successfully replacing several variables inside of the config file, but it seems any time we use a conditional, nothing is returned. I looked through github at the Octostache project to see if I was using the syntax properly, and I feel like I am.

Here is a snippet of the config where we aren’t getting anything output. I would expect an echo if I didn’t properly write it, or one of the values to be displayed.

#{if Production}#{else}#{/if}

I have a variable called Production with a value of False. I am using OD 2.6.5.1010.

What am I doing wrong?

Thanks,
Kyle

Hi Kyle,

Thanks for getting in touch! If I am reading this right, you have your variable production only set to false but no setting for true scoped to the Production environment?
Are you assuming we will know when it is production and change your variable value? Because that won’t happen.
If you have it set properly when you run on production and have it set to true it will output anything between the values.
Also do you have the config file defined in your variable substitution feature?

Thanks!
Vanessa

Hi Vanessa,

You are correct that I only have the variable set to False. Right now, I am just doing the trial on a few machines and I haven’t made it to testing the production-like deployment (because that will involve me spinning up a bunch of machines on AWS).

No, I am not assuming OD will know when it is in production. I just haven’t scoped any of the variables for the production deployment yet because I am working on getting the first level DEV (before I I try to get the QA, Product Acceptance, User Acceptance, Performance Testing, and Production deployments validated).

I’m sorry for being too vague with my description, that is my fault. Here is some more information to help detail out what I am getting at.

Inside of the NuGet packages that I am trying to deploy exists a file called Octopus.config. This is the template configuration file with the variables to substitute during the deployment. Inside the deployment step, I have it running a Pre-deployment script that removes the config file we use for development and copies the template config into that location so we can replace the variables. The next part of the deployment step is to Substitute variables in files. I have many variables in our template config file that I am having problems with. All of the variables get replaced. The problem I am having is the variables that are conditional don’t actually do anything, or get replaced with anything. They aren’t echoed so I feel like I have the syntax properly written. The conditional I showed above is an if-else so I feel like something should be in the configuration file after the variables are substituted (I put spaces in and copied it below to show it better). The question I have is: if the file is substituting variables (so I know it is being executed), and I am not getting anything echoed back to me (so I assume I have the syntax properly written), and there is nothing left in the configuration file after the substitution, what am I doing wrong?

  <recipientWhiteList> 
    #{if Production}
            <!--<item address="*@<OUR_DOMAIN>"/>-->
    #{else}
            <item address="*@<OUR_DOMAIN>"/>
    #{/if} 
  </recipientWhiteList>

I hope I provided enough information, if not please let me know and I can get you those details.

Thanks,
Kyle

Hi Kyle,

Ahh. So #{else} isn’t supported. You would need 2 tags and 2 variables such as Production and NotProduction wrapped around each chunk of code, with NotProduction scoped to the environments that you want the config to be part of.

Vanessa

Hi Vanessa,

Oops, that’s my fault. I guess I was misreading the ConditionalToken class (https://github.com/OctopusDeploy/Octostache/blob/master/source/Octostache/Templates/ConditionalToken.cs) or it’s only used inside the framework or maybe it is a 3.0 thing (which would be AWESOME!!!).

Thank you for all your help Vanessa!!!

Have a great day!
Kyle

Hi Kyle,

It doesn’t look like you read it wrong, and yeah based off that code it looks like it should be available, but its no where in the documentation, which leads me to a few guessed conclusions. 1. it only works in certain step types such as email steps (this can happen), 2. its never worked properly so was never documented (unlikely but hey while we are guessing), 3. It just bugged and was never documented and should work.

Either way I’ve created a task in GitHub to investigate why its in the code and why it doesn’t work, or where it does work etc. https://github.com/OctopusDeploy/Issues/issues/1583
My work around would be what is suggested below.

Vanessa

Hi Vanessa,

Now that I am more familiar with the variable substitution, I realize there is a way to do this, without using else. Using the unless keyword will work as a “falsey” statement (basically executing the else I wanted to run). I just have to have the if and unless evaluate the exact same criteria and it works I would expect.

I will close the ticket now.

Thanks,
Kyle