How to inject dynamic yaml sections into helm values file

I have a helm values file and I want to inject arbitrary yaml sections defined in Octopus variables. Consider the following example:

  #{if AppSettings.AdditionalAppSettings}
  #{AppSettings.AdditionalAppSettings | Replace "\n" "\n  "}

The preceding code does not work because the Replace filter is not working as I expect it to be. I am probably overseeing something here. It will produce an output like this:

  value1: key1\n  value2: key2\n  

The replaced value contains the actual literal "\n " instead of a new line and whitespace. I am basically trying to achieve a similar behavior to helm’s nindent function.

There is a similar issue I found on this forum: Preserve Indentation when inserting variable lists in a template. The suggested answer was to use the YAML replacement feature. However, this feature is currently not available for the Upgrade Helm Chart built in step, which I am using here. But even if it was available, I am still interested in knowing whether we can achieve this behavior with variable substitution.

In summary, I want to know

  • If I am using the Replace filter in a wrong way
  • What is the best practice / guideline to handle such a use case?
1 Like

Hi Taha,

Thanks for getting in touch! I think Octopus is applying your variable as a literal string, which is causing the new-line characters to not be respected. I think the best option would be to consider using our Structured Configuration Variable feature in place of the Octopus substitution syntax with filters that you’re currently using.

With the structured configuration variable feature you can have your Helm Chart pre-configured with the correct format and placeholder value for value1 & value2 inside of appSettings, which Octopus will substitute during deployment.

Here’s an example of how your Helm Chart could be configured before Octopus evaluates any values.

    value1: PlaceholderKey1
    value2: Placeholderkey2

Then you create two new project variables.

Variable Value
appSettings:value1 Key1
appSettings:value2 Key2

When Octopus deploys the Helm Chart, it will substitute any corresponding values it finds. This is currently our preferred method for hierarchical substitution for use with YAML / JSON files.

Let me know if this helps or if you have any questions at all on implementing this.

Best regards,

Hi Daniel!

Thank you for the quick response. But unfortunately, the Upgrade Helm Chart step Deploy a Helm chart | Documentation and Support does not support structured configuration.

Also, I wonder if structured configuration supports injecting multi-line strings. We have deep nested variables with lots of optional keys. For this reason, we decided not to use a single variable for each value, rather a variable for each nested object. See screenshot for an example.


Just a heads up that I’m currently looking into this. I misread your initial request where you pointed out that the structured configuration feature doesn’t work for this step. I’m currently setting up a reproduction to test the best way of substituting these values in your deployment.

I’ll get back to you soon with my findings.

Best regards,


Any update on this?


Thanks for getting back, I’m sorry for the delay in replying here. I was able to reproduce this on my end, but I’ve yet to hear back from the developers as to whether this is a bug or intended behaviour. I’ll follow up with the team and see if I can get some definitive answer and if it’s a bug/oversight, get it addressed.

Best regards,

1 Like