I can believe fly.

Wednesday, February 15, 2017

Jenkins SSH 调查

man bash,看“Invocation”,关于交互式shell与非交互式shell的差别。还有登录shell与非登录shell的差别。

man ssh, 看到“If command is specified, it is executed on the remote host instead of a login shell.”

interactive login shell, or as a non-interactive shell with the --login option
     /etc/profile首先加载
     接着
     ~/.bash_profile, ~/.bash_login, and ~/.profile
     注意:是按顺序尝试,只加载遇到的第一个

When an interactive shell that is not a login shell is started
     /etc/bash.bashrc首先加载
     接着
     ~/.bashrc

/etc/bash.bashrc:
# System-wide .bashrc file for interactive bash(1) shells.

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

/etc/profile:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), …).


实际上,为了避免代码重复,通常
.profile会source .bashrc
/etc/profile会source /etc/bash.bashrc


Login profile files

When the SSH slaves plugin connects to a slave, it does not run an interactive shell. Instead it does the equivalent of your running "ssh slavehost command..." a few times, eventually to run "ssh slavehost java -jar …".
Jenkins SSH Slave的登录:只会调用/etc/bash.bashrc和.bashrc,并且是non-interactive的。在原始的.bashrc的第一 句话,就return了。

http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
Mac OS X 是例外:
An exception to the terminal window guidelines is Mac OS X’s Terminal.app, which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. Other GUI terminal emulators may do the same, but most tend not to.

https://help.ubuntu.com/community/EnvironmentVariables

Note: Variable expansion does not work in /etc/environment.

这一句很重要,在/etc/environment里写 CLASSPATH=$CLASSPATH:xxxx:xxxxx,会导致Jenkins解析环境变量时死循环,就在于变量不展开。 

落款2014.02.26

No comments: