Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Octopus Deploy variable substitution in appsetings.json

How do I get a json variable replaced without it being placed in quotes ? The appsettings.json contains a list of server names, server:names is an Octopus deploy variable that need to be replaced on deployment.

{
"server":
    {
        "names":  [ "#{server:names| JsonEscape}" ]
    }
}

Octopus variable is configured like this: server:names with value: "server_x", "server_y"

The result for names after replacement should be:

"names":  [ "server_x", "server_y" ]

but instead I'm getting the following result which makes the json file invalid:

"names":  [ ""server_x", "server_y"" ] 

Appsettings.json needs the quotes but should be replaced by the Octopus Deploy. I can't use the Json Configuration Variables feature, it needs to substitute the variables.

Any ideas how I would go about this ?

like image 788
Oysio Avatar asked Oct 18 '25 02:10

Oysio


1 Answers

If you can't use the Json Configuration Variables (now Structured configuration variables feature), I think the way to go is:

  • change the variable value to ["server_x", "server_y"]
  • change the line in the JSON file to "names": #{server:names}

Note: JsonEscape is for escaping values that will go into JSON strings, not full JSON elements or nodes.

If you need to escape the server names, you may need to do that for the server names individually.

In your original example, you can remove the extra "s to get valid JSON. Or using my example above without JsonEscape produces the expected structure.

Screenshot of script

Screenshot of output

like image 83
ryan.rousseau Avatar answered Oct 19 '25 21:10

ryan.rousseau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!