Concatenate two Octopus variable with escape character

I want the “path” variable resolve to “C:\Log\Project1\log.txt” in the config file in the below configuration section I have copied where {LoggingDir}=“C:\Log” and {Octopus.Project.Name}=“Project1”. Currently the way it is defined Octopus is throwing error and build is failing.

"WriteTo": [
    "Name": "File",
    "Args": {
      "path": "#{LoggingDir}\\#{Octopus.Project.Name}\\log.txt", //This is the path variable
      "rollingInterval": "Day",
      "retainedFileCountLimit": 14

Thanks for getting in touch. I’m guessing that it is failing due to the string ending up looking like:


Which is not valid in the JSON as the first \ needs to be escaped. You can do this by using the JsonEscape filter. i.e.

"path": "#{LoggingDir | JsonEscape}\\#{Octopus.Project.Name | JsonEscape}\\log.txt",

Thanks Robert,
that worked like a charm :smiley:


1 Like

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