Wrong Environmental variables in $PATH from Octopus server

Hi,

Deployments are failing since the environmental variables octopus server are getting from the path are no complete.
For example “ip” command works as expected locally on the server but it is not found on the path from the Octopus server

Output from Octopus server:
Hostname server1.example.com
Whoami octopus
Echo “$PATH” /usr/local/bin:/usr/bin
Which ip which: no ip in (/usr/local/bin:/usr/bin) Error
The remote script failed with exit code 1 Fatal

Output logged in locally on the server
[octopus@server1~]$ hostname;whoami;echo “$PATH”; which ip
server1.example.com
octopus
/usr/local/bin:/usr/bin:/usr/local
/usr/local/ip
Why Octopus server is not getting the right path ?

Tentacles are fully updated. Octopus verison 2020.1.18

Hi jscvictormanuel,

Thank you for reaching out to us with your query.

Octopus will be using the $PATH variable that is provided to it by the operating system. The most likely explanation for the difference is that the server is configured to provide a different path depending on the user, connection method or some other factor.

Can you please advise on the following?

  • Is this script running directly on the Octopus Server, in a worker or on a Tentacle? Is any form of containerisation in use? If a Tentacle which connection type is being used?

  • When you run the commands manually are you logged in using the same method as Octopus? For example, if Octopus is connecting using SSH, do you see the same issue when using SSH?

  • Has this process worked previously? If yes, has anything changed recently (such as an operating system upgrade)?

Best Regards,

Charles

Hi Charles,
Thank you for your quick response.

  • The script is running in a SSH Linux Tentacle

  • Yes, local logging (where the $PATH is show as it is, and it works as expected) is done via SSH, same as the Octopus connection

  • The difference between when it works and it does not (different machines), is the user used to connect the tentacle. If the user is “root”, Octopus get the $PATH right, if the user is “Octopus”, Octopus server strips out the " /usr/local " from the $PATH

Have a nice weekend

Hi jscvictormanuel,

Thank you for getting back to me.

It sounds like Octopus is logging in as a different user. Would you be able to confirm what happens in each of the following situations?

  • If you connect manually, using SSH, as the user “Octopus”, what is the value of $PATH?
  • If you connect manually, using SSH, as the user “root”, what is the value of $PATH?
  • If Octopus connects, using SSH, as the user “Octopus”, what is the value of $PATH?
  • If Octopus connects, using SSH, as the user “root”, what is the value of $PATH?

Please let me know if you have any questions.

Best Regards,

Charles

Hello Charles,

Yes we are using an Octopus user to connect to the tentacles rather than root

  • Local SSH Octopus user $PATH:
    /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/octopus/.local/bin:/home/octopus/bin

  • Local SSH root user $PATH:
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

  • Octopus connect via Octopus user $PATH:
    /usr/local/bin:/usr/bin

  • Octopus connect via root user $PATH:
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

Thank you

Hi @jscvictormanuel!

Just jumping in for Charles here, as he’s away this week.

What’s likely happening here is that these are being set in your .bashrc file, which has an explicit call to exit if bash is not being run interactively when called through Octopus (but it is via an interactive SSH session).

If you look in your .bashrc, you should see the lines at or near the top:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

To get around this, you could put your path mods in an $HOME/.ssh/environment file, or if this changes a lot, you could add it before the above code block to set it even for non-interactive sessions.

I hope this helps!

Hi justin!

Sorry for taking so long to come back to you.

You were right, we did find the issue was related with what $PATH were being loaded remote vs local.

It is solved,

Thank you very much

Hi jscvictormanuel,

Thank you for letting us know, we’re glad to hear that this is working.

If you have any other questions please reach out to us again.

Best Regards,

Charles

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