Octopus Variable Partial replacement

Hi Team,

I have multiple packages in my Octopus project and each package has its own appsettings.json file.

I have a key value in all appsettings.json as below

“path”: “D:\ApplicationLogs\package1\package1Tests-.log”
“path”: “D:\ApplicationLogs\package2\package2-.log”
“path”: “D:\ApplicationLogs\package3\package3_new-.log”

I want to replace the drive (D:) from the value with some share path for different environments.

We can manage different environments through the scope feature, but I cannot replace the substring of the value.

It would be great if you can suggest the solution or work around for the issue

Greetings! Have you seen our Structured Configuration Variables feature? This one will allow you to create Project variables to replace items in JSON such as what you’ve stated. If you take a gander at Structured configuration variables - Octopus Deploy, you’ll see how the variables need to be named so that the replacement will work correctly.

Does this help?



PS. Discorse renamed the second link, that one goes directly to a section of the documentation, sorry 'bout that.

Hi Shawn,

Yes, I have seen this article. The problem here is that the octopus is replacing the complete value of the key. My requirement is to replace the Substring of the value already available in the appsettings.json

As given example in the article, “tempImageFolder”: “C:\temp\img”,

I’ll create a variable tempImageFolder and give the value as D:\temp\img. This works fine. This replacement works perfectly fine

I want to know if I can give value for the variable as Replace(tempImageFolder, “C:”, “#{FileSharePath}\temp\img”)

I don’t want to replace complete value as developers might be using something they have in their local.

Oh! Okay, I’m following now, thank you for clarifying. How about something like this, create a new Octopus variable called DriveLetter (or something like that). For the tempImageFolder variable, you could assign the value of #{DriveLetter}\temp\img. DriveLetter would be scoped per environment as you stated and change per environment. Would something like that work?



I am sorry Shawn, that won’t work as I would be hard coding the value of temp\img in my variable’s value. I want to use the value which is coming from appsettings.json file and replace the drive letter.

Let’s say I have 3 packages and each package has it’s own appsettings.json file like below

Key Value in Package1 file
“path”: “D:\ApplicationLogs\package1\package1Tests-.log”

Key Value in Package2 file
“path”: “D:\ApplicationLogs\package2\package2-.log”

Key Value in Package3 file
“path”: “D:\ApplicationLogs\package3\package3_new-.log”

Now I want that only the drive letter to be replaced from each value and the rest of the string should remain as it is in the deployed package.

Thank you for your patience as I consider what might work for you. I have one suggestion that may be able to fit your needs. If you are able (or already are) to use a local appsettings file for local development, we could alter the “real” appsettings file to contain some OctoStache syntax specifically for the drive letter portion of the value (Variable Recommendations - Octopus Deploy). For example, your appsettings.local.json file could look like


Then your appsettings.json file could look like


You would then have a Octopus Project variable called Project.DriverLetter which you could make any value. You would need to enable the Substitute variables in templates feature. That should get you your desired result.