Substitute Octopus Inbuilt/System Variable in appsettings.json

Hello all,

I have an appsettings.json file in our Github Repo that I would like to define Octopus inbuilt/system variable that could be substituted during deployment to our K8s cluster.

In the appsettings.json, the variable “#{Octopus.Release.Number}” was substituted successfully. I would like to define another inbuilt variable in appsettings.json in such a way like “#{Octopus.ProjectID/Slug.VariableName}” so as for it to substitute a Variable name defined in Octopus Server. The VariableName is in a libraryset, with different Key/Value scoped against all the environments in our K8s cluster.

Any help on how to define this in my appsettings.json will be gladly appreciated. I read through System variables - Octopus Deploy but couldn’t get what best solve this situation. I also looked through the swagger page of Octopus to look at all the inbuilt/system variable Octopus has but nothing has been able to solve this issue.

Thank you.

Hi @akeem.ogunfowora,

Welcome and thanks for posting your question! If you already have a Library Variable Set defined, then you can include that in your project as described in the documentation. Then you can reference that variable as you normally would any other variable you’ve created.

For example, on our Samples instance (which you can log into as guest) in the Target - Kubernetes space → GCP Project group → Web App project we have included a K8s Library Variable Set. I’ve included a snippet of some of the values below.

Then if you look at the process you can see places where we use those values, such as in the Service section.

This process would be similar to what you would want to do for your appsettings.json file.

You could also try to utilize the OctopusPrintVariables and OctopusPrintEvaluatedVariables and set them to true in your Project variables (only temporarily for debugging) to see what variables there are and what they evaluate to if that helps. These are described under the User-modifiable settings heading on that page you linked.

I hope I understood your question correctly, but let me know if I can be of further assistance.

Thanks,
Mark

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