Passing strings to Harness containing ${} as the Value

Hello Everybody.


This article walks you through the details of how you can pass variables with values defined between “${}” to the Helm Type Charts or K8s Type Manifests.


When trying to pass a Variable to Harness as part of the Manifest with a value of ${test_val} it does not render as expected and fails with an Error saying “Bad Substitution”. This is because Harness has a predefined resolution set for vars starting with a dollar symbol and brackets ${<val>} and tries to resolve them instead of treating the value as a string where it fails with the Error mentioned above.

It is a valid requirement to be able to structure the YAML to be deployed using variables so that they can be templatised. In order to achieve this, we would first need to create a Service Variable and provide its value as the String you are trying to pass :

Then you will need to reference this Service Variable which was created above in the Helm Chart Values YAML as below; this way it will resolve the variable as expected and display the same when it is rendered treating them like a string :

collaboratorUrl: ${serviceVariable.test}

We can now go ahead and Deploy the Helm Chart via Harness and here when looking at the Rendered YAML you will notice that the variable was resolved as a string :

This method explains how User defined variables can be created on the Harness Service level to allow the Render to work in cases where a variable contains values defined between “${}”.