#1468  wrong environment with the SSH step
Closed
bufferUnderrun opened 10 months ago

Hi,

There is something strange when using the SSH step. The environment is not the same as connecting to ssh the classic way.

classic way, it's OK

ssh user@server
% ruby -v
ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin22]

using OneDev step, it's WRONG

% ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin22]

classic way inside 1dev/ssh-client image, it's OK

$ podman run -it --rm --name ssh -v "/home/user/.ssh:/root/.ssh/" 1dev/ssh-client
% ssh user@server
% ruby -v
ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin22]

**Question ** : how do you connect to ssh inside the command step ? and why i've got a different environment between classic manual ssh and onedev ssh step.

Thanks for your help

Robin Shen commented 10 months ago

OneDev uses heredoc to do the job:

ssh user@server << EOF
ruby -v
EOF

Please test above command to see if it prints the same.

bufferUnderrun commented 10 months ago

i confirm the difference come from heredoc

with heredoc, incorrect

ssh user@server << EOF                                                           
heredoc> ruby -v
heredoc> EOF
Pseudo-terminal will not be allocated because stdin is not a terminal.
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin22]

without heredoc, correct

ssh user@server
~ % ruby -v
ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin22]

As i test my command inside ssh (works) and then copy/paste into onedev ssh step (do not work then), that's why i break my CI/CD.

Do you have any workaround for heredoc having the same behaviour as inside an ssh ?

Robin Shen commented 10 months ago

When calling ssh to execute remote commands (heredoc or other approaches), it has no way to set up environments included in .bashrc or .profile. You will need to set up them explicitly in commands.

bufferUnderrun commented 9 months ago

so i manually call source ~/.zshrc before all commands and it works.

thanks.

Maybe it should be written somewhere in documentation to source profil to avoid others facing same issue.

bufferUnderrun changed state to 'Closed' 9 months ago
Previous Value Current Value
Open
Closed
Robin Shen commented 9 months ago

Yes, I will mention this in inline help of the step.

issue 1 of 1
Type
Bug
Priority
Normal
Assignee
Affected Versions
8.5.9, 8.5.2
Issue Votes (0)
Watchers (3)
Reference
onedev/server#1468
Please wait...
Page is in error, reload to recover