Preserve Indentation when inserting variable lists in a template

Say I have an octopus variable that has a list of items in it. For example, the variable is called ContainerEnvironmentVariables and it has the following key values pairs in it:

Environment: Dev
LoggerService: https://myloggerservice.com
DbConnectionString: myDbConnectionString

I have a spot in my yaml that I insert this string. It looks like this:

env:
  #{ContainerEnvironmentVariables}

Unfortunately, after the variable substitution it looks like this:

env:
  Environment: Dev
LoggerService: https://myloggerservice.com
DbConnectionString: myDbConnectionString

The first one is correctly indented and the others are not. Yaml is whitespace sensitive, so I have to get the spaces in there.

Does the Octopus Deploy Template system support a “Preserve Indentation” kind of feature?

Hi @OctopusSchaff,

Thanks for getting in touch! So the variable replacement here is a fairly simple process. It is basically doing an exact replacement in your file. So if you have new lines in your variable, the first line will be indented just as #{ContainerEnvironmentVariables} is. Your subsequent lines are technically each on a new line and Octopus will apply that new line in the transformation.

You have a few options available to resolve this. As a quick workaround, you could try adding the spacing to the variable in Octopus so it applies the indentation as a part of the substitution.

A tidier solution would be to use the YAML replacement feature. Our documentation has details on how you can do this, though I have an example below of what it would look like for you.

For an Octopus variable named env

{"Environment":"Dev","LoggerService":"https://myloggerservice.com","DbConnectionString":"myDbConnectionString"}

This method should keep the YAML formatting.

Let me know if this helps or if you have any questions or issues with this.

Best regards,
Daniel

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