How to remove trailing directory separators after variable substitution?

Hi Octo team,

We are substiuting variables in our files with filters -
#{Octopus.Tentacle.Agent.ApplicationDirectoryPath | Replace “\” “/”}/#{Octopus.Environment.Name}/abc.txt

On some servers it does D:/Octopus/Applicatons/Dev/abc.txt and on others D:/Octopus/Applicatons//Dev/abc.txt
(Notice extra directory separator)

How do you suggest we fix this?

Hi @Nikhil_Agrawal,

Thank you for contacting Octopus Support.

I hope you don’t mind, I have a few clarifying questions:

  • What version of Octopus Server are you running?
  • What OS, Octopus Tentacle version, and Calamari version are installed on the working targets?
  • What OS, Octopus Tentacle version, and Calamari version are installed on the non-working targets?

Let me know at your earliest convenience.

Regards,
Donny

Hi @donny.bell,

Thanks for replying,

The Octo server version is 2019.12.0 LTS

The tentacle where there are no extra trailing spaces has
OS - Windows 2012 R2 Standard
Tentacle Version - 5.0.9
Calamari Version - 8.1.3

The tentacle where there are extra trailing spaces has
OS - Windows 2016 Standard
Tentacle Version - 5.0.12
Calamari Version - 8.1.3

Cheers,
Nikhil

Hi @Nikhil_Agrawal,

Thank you for getting back to me.

Is the same project running on both the working and non-working targets? Is the variable substitution happening on the exact same file?

Would it be possible for you to share a raw task log with variable logging turned on for a working and non-working target?

Here is a secure upload link for your convenience.

I look forward to hearing back from you.

Regards,
Donny

Hi @donny.bell,

Please find my replies inline.

[DB]: Is the same project running on both the working and non-working targets? Is the variable substitution happening on the exact same file?
[NA]: Yes, variable substitution is happening in the same file on both working and non-working targets for the same project.

[DB]: Would it be possible for you to share a raw task log with variable logging turned on 2 for a working and non-working target?
[NA]: I have attached project json & raw deployment logs. The logs are created for a release, deployed on a working target (L15387) and a non-working target (L30494).


On a high level, the project’s 2nd step (“Set Up Component”) is a PS script step which

  1. Downloads tools-infra-apps-nginx nuget package.
  2. Replaces values in .conf files.
  3. Runs a script present in downloaded nuget.

The contentFiles\nginx.conf contains following-

include #{Octopus.Tentacle.Agent.ApplicationDirectoryPath | Replace "\\" "/" }/#{Environment}/frontier-nginx-conf/current/nginx.conf;

On
L15387 - D:/Octopus/Applications/Dev/frontier-nginx-conf/current/nginx.conf;
L30494 - D:/Data/Octopus/Applications//Dev/frontier-nginx-conf/current/nginx.conf;

Thanks,
Nikhil

p.s. Thanks for this cool trick of turning on variable logging and exporting the task log. Learning something new about Octo every day. :+1:

Hi @Nikhil_Agrawal

Thank you for getting back to me.

Could you try the following to see if this resolves the issue?

#{Octopus.Tentacle.Agent.ApplicationDirectoryPath | Replace "\\$" "" | Replace "\\" "/" }

Let me know if that works in this case.

Regards,
Donny

Hi @donny.bell,

Thanks for workaround. Sure, I’ll give it a try.

If this works, it will be a fix only for this script. Is there any way possible to fix tentacle itself for this script and all other scripts?

Thanks,
Nikhil

Hi @Nikhil_Agrawal,

Thank you for the quick response.

I think I was able to figure out the root cause.

In the Tentacle.config file (located in the Home Directory defined in Tentacle Manager under a folder with the Tentacle’s name), the Tentacle.Deployment.ApplicationDirectory key defines this value. I tested and confirm that you may change the value, stop the tentacle service, then restart the tentacle service to make the change take effect with no changes in Octopus Server.

This should take care of the root of the issue. However, depending on which is easier, you have the workaround option as well.

If you have any additional questions or if there is anything else I can assist with, please let me know.

Regards,
Donny

Hi @donny.bell,

It worked! Thanks for your help.

Cheers,
Nikhil

1 Like

Hi @Nikhil_Agrawal,

Thank you for getting back to me. I’m glad to hear that helped.

For reference, I created a GitHub issue for this as I feel like Octopus should handle this a little more gracefully.

If there is anything else we can assist with, please let us know.

Regards,
Donny

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