Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-17157

Enviroment variables are not loaded in ssh using cygwin

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When configuring an ssh slave which runs on cygwin, the environment variables are not loaded.
      However I do know that ~/.bash_profile is executed and sourced, because it will display echo commands in the output console if I insert them there.
      Also things like PATH and PWD do not exist, causing any command to fail.

      Output from the ssh looks like this (note remote environment is empty):

      [03/11/13 18:40:35] [SSH] Opening SSH connection to vmbld-vc902:22.
      
      [03/11/13 18:40:36] [SSH] Authentication successful.
      [03/11/13 18:40:36] [SSH] The remote users environment is:
      [03/11/13 18:40:37] [SSH] Checking java version of java
      
      Couldn't figure out the Java version of java
      
      [03/11/13 18:40:37] [SSH] Checking java version of /usr/bin/java
      Couldn't figure out the Java version of /usr/bin/java
      
      [03/11/13 18:40:38] [SSH] Checking java version of /usr/java/default/bin/java
      
      Couldn't figure out the Java version of /usr/java/default/bin/java
      
      [03/11/13 18:40:38] [SSH] Checking java version of /usr/java/latest/bin/java
      Couldn't figure out the Java version of /usr/java/latest/bin/java
      
      [03/11/13 18:40:38] [SSH] Checking java version of /usr/local/bin/java
      Couldn't figure out the Java version of /usr/local/bin/java
      
      [03/11/13 18:40:39] [SSH] Checking java version of /usr/local/java/bin/java
      
      Couldn't figure out the Java version of /usr/local/java/bin/java
      
      [03/11/13 18:40:39] [SSH] Checking java version of /home/packaging/test/jdk/bin/java
      Couldn't figure out the Java version of /home/packaging/test/jdk/bin/java

      If I forcefully point the JAVA_PATH to java (located at /usr/bin/java) I get:

      [03/11/13 18:59:55] [SSH] Opening SSH connection to vmbld-vc902:22.
      
      [03/11/13 18:59:55] [SSH] Authentication successful.
      [03/11/13 18:59:56] [SSH] The remote users environment is:
      
      [03/11/13 18:59:57] [SSH] Starting sftp client.
      [03/11/13 18:59:57] [SSH] SFTP failed. Copying via SCP.
      
      [03/11/13 18:59:58] [SSH] Remote file system root /home/packaging/test does not exist. Will try to create it...
      Failed to create /home/packaging/test
      
      [03/11/13 18:59:58] [SSH] Copying latest slave.jar...
      hudson.util.IOException2: Could not copy slave.jar into '/home/packaging/test' on slave
      	at hudson.plugins.sshslaves.SSHLauncher.copySlaveJarUsingSCP(SSHLauncher.java:800)
      	at hudson.plugins.sshslaves.SSHLauncher.copySlaveJar(SSHLauncher.java:759)
      	at hudson.plugins.sshslaves.SSHLauncher.launch(SSHLauncher.java:468)
      	at hudson.slaves.SlaveComputer$1.call(SlaveComputer.java:222)
      	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
      	at java.util.concurrent.FutureTask.run(Unknown Source)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      	at java.lang.Thread.run(Unknown Source)
      Caused by: java.io.IOException: Error during SCP transfer.
      	at com.trilead.ssh2.SCPClient.put(SCPClient.java:523)
      	at hudson.plugins.sshslaves.SSHLauncher.copySlaveJarUsingSCP(SSHLauncher.java:798)
      	... 8 more
      Caused by: java.io.IOException: Remote scp terminated unexpectedly.
      	at com.trilead.ssh2.SCPClient.readResponse(SCPClient.java:50)
      	at com.trilead.ssh2.SCPClient.sendBytes(SCPClient.java:140)
      	at com.trilead.ssh2.SCPClient.put(SCPClient.java:519)
      	... 9 more
      [03/11/13 18:59:59] [SSH] Connection closed.

      Cygwin verion 1.5.24-2
      SSH from the machine that runs Jenkins to the machine works fine.

      I know this is not a lot for recreation, If you need any other logs to troubleshoot them please specify in the comments

        Attachments

          Activity

          Hide
          dborin David Borin added a comment - - edited

          I have tried updating

          /home/<user>/.bashrc
          /home/<user>/.bash_profile
          /home/<user>/.profile
          /etc/profile
          /etc/bash.bashrc

          And none of them are reflected in the log output. I'm unable to determine how Jenkins is getting the env vars once it is able to SSH into my Cygwin Windows machine. If I knew what environment file it was reading, I could perhaps work around this.

          Here is the output from the Jenkins UI log console...note that there are some env vars specified

          [04/16/13 21:22:35] [SSH] Authentication successful.
          [04/16/13 21:22:35] [SSH] The remote users environment is:
          ALLUSERSPROFILE='C:\ProgramData'
          BASH=/bin/bash
          BASHOPTS=cmdhist:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
          BASH_ALIASES=()
          BASH_ARGC=()
          BASH_ARGV=()
          BASH_CMDS=()
          BASH_EXECUTION_STRING=set
          BASH_LINENO=()
          BASH_SOURCE=()
          BASH_VERSINFO=([0]="4" [1]="1" [2]="10" [3]="4" [4]="release" [5]="i686-pc-cygwin")
          BASH_VERSION='4.1.10(4)-release'
          COMPUTERNAME=GLIM-WIN2K12-1
          COMSPEC='C:\Windows\system32\cmd.exe'
          CYGWIN='binmode ntsec'
          DIRSTACK=()
          EUID=500
          GROUPS=()
          HOME=/home/Administrator
          HOMEDRIVE=C:
          HOMEPATH='\cygwin\home\Administrator'
          HOSTNAME=GLIM-WIN2K12-1
          HOSTTYPE=i686
          IFS=$' \t\n'
          LOGNAME=Administrator
          LOGONSERVER='
          GLIM-WIN2K12-1'
          MACHTYPE=i686-pc-cygwin
          MAIL=/var/spool/mail//Administrator
          OPTERR=1
          OPTIND=1
          OS=Windows_NT
          OSTYPE=cygwin
          PATH=/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/bin
          PATHEXT='.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC'
          PIPESTATUS=([0]="0")
          PPID=3076
          PROGRAMFILES='C:\Program Files (x86)'
          PS4='+ '
          PWD=/home/Administrator
          SHELL=/bin/bash
          SHELLOPTS=braceexpand:hashall:interactive-comments
          SHLVL=1
          SSH_CLIENT='10.14.209.192 52903 22'
          SSH_CONNECTION='10.14.209.192 52903 10.14.210.91 22'
          SYSTEMDRIVE=C:
          SYSTEMROOT='C:\Windows'
          TERM=dumb
          UID=500
          USER=Administrator
          USERDOMAIN=GLIM-WIN2K12-1
          USERNAME=Administrator
          USERPROFILE='C:\Users\Administrator'
          WINDIR='C:\Windows'

          Here is the output when I simply SSH into the machine. They differ and in this one, the path to the Java JDK works.

          $ env | sort
          _=/usr/bin/env
          ALLUSERSPROFILE=C:\ProgramData
          COMPUTERNAME=GLIM-WIN2K12-1
          COMSPEC=C:\Windows\system32\cmd.exe
          CYGWIN=binmode ntsec
          HOME=/home/Administrator
          HOMEDRIVE=C:
          HOMEPATH=\cygwin\home\Administrator
          HOSTNAME=GLIM-WIN2K12-1
          INFOPATH=/usr/local/info:/usr/share/info:/usr/info:
          LANG=en_US.UTF-8
          LOGNAME=Administrator
          LOGONSERVER=
          GLIM-WIN2K12-1
          MAIL=/var/spool/mail//Administrator
          MANPATH=/usr/local/man:/usr/share/man:/usr/man::/usr/ssl/man
          OLDPWD=/home/Administrator
          OS=Windows_NT
          PATH=/usr/local/bin:/usr/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/bin:/blah/:/cygdrive/c/Program Files/Java/jdk1.7.0_17/bin/
          PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
          PRINTER=Microsoft XPS Document Writer
          PROGRAMFILES=C:\Program Files (x86)
          PS1=[\e]0;\w\a]\n[\e[32m]\u@\h [\e[33m]\w[\e[0m]\n\$
          PWD=/home/Administrator
          SHELL=/bin/bash
          SHLVL=1
          SSH_CLIENT=10.20.76.6 55831 22
          SSH_CONNECTION=10.20.76.6 55831 10.14.210.91 22
          SSH_TTY=/dev/pty1
          SYSTEMDRIVE=C:
          SYSTEMROOT=C:\Windows
          temp=
          TEMP=/tmp
          TERM=xterm
          tmp=
          TMP=/tmp
          TZ=Etc/GMT
          USER=Administrator
          USERDOMAIN=GLIM-WIN2K12-1
          USERNAME=Administrator
          USERPROFILE=C:\Users\Administrator
          WINDIR=C:\Windows

          Show
          dborin David Borin added a comment - - edited I have tried updating /home/<user>/.bashrc /home/<user>/.bash_profile /home/<user>/.profile /etc/profile /etc/bash.bashrc And none of them are reflected in the log output. I'm unable to determine how Jenkins is getting the env vars once it is able to SSH into my Cygwin Windows machine. If I knew what environment file it was reading, I could perhaps work around this. Here is the output from the Jenkins UI log console...note that there are some env vars specified [04/16/13 21:22:35] [SSH] Authentication successful. [04/16/13 21:22:35] [SSH] The remote users environment is: ALLUSERSPROFILE='C:\ProgramData' BASH=/bin/bash BASHOPTS=cmdhist:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath BASH_ALIASES=() BASH_ARGC=() BASH_ARGV=() BASH_CMDS=() BASH_EXECUTION_STRING=set BASH_LINENO=() BASH_SOURCE=() BASH_VERSINFO=( [0] ="4" [1] ="1" [2] ="10" [3] ="4" [4] ="release" [5] ="i686-pc-cygwin") BASH_VERSION='4.1.10(4)-release' COMPUTERNAME=GLIM-WIN2K12-1 COMSPEC='C:\Windows\system32\cmd.exe' CYGWIN='binmode ntsec' DIRSTACK=() EUID=500 GROUPS=() HOME=/home/Administrator HOMEDRIVE=C: HOMEPATH='\cygwin\home\Administrator' HOSTNAME=GLIM-WIN2K12-1 HOSTTYPE=i686 IFS=$' \t\n' LOGNAME=Administrator LOGONSERVER=' GLIM-WIN2K12-1' MACHTYPE=i686-pc-cygwin MAIL=/var/spool/mail//Administrator OPTERR=1 OPTIND=1 OS=Windows_NT OSTYPE=cygwin PATH=/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/bin PATHEXT='.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC' PIPESTATUS=( [0] ="0") PPID=3076 PROGRAMFILES='C:\Program Files (x86)' PS4='+ ' PWD=/home/Administrator SHELL=/bin/bash SHELLOPTS=braceexpand:hashall:interactive-comments SHLVL=1 SSH_CLIENT='10.14.209.192 52903 22' SSH_CONNECTION='10.14.209.192 52903 10.14.210.91 22' SYSTEMDRIVE=C: SYSTEMROOT='C:\Windows' TERM=dumb UID=500 USER=Administrator USERDOMAIN=GLIM-WIN2K12-1 USERNAME=Administrator USERPROFILE='C:\Users\Administrator' WINDIR='C:\Windows' Here is the output when I simply SSH into the machine. They differ and in this one, the path to the Java JDK works. $ env | sort _=/usr/bin/env ALLUSERSPROFILE=C:\ProgramData COMPUTERNAME=GLIM-WIN2K12-1 COMSPEC=C:\Windows\system32\cmd.exe CYGWIN=binmode ntsec HOME=/home/Administrator HOMEDRIVE=C: HOMEPATH=\cygwin\home\Administrator HOSTNAME=GLIM-WIN2K12-1 INFOPATH=/usr/local/info:/usr/share/info:/usr/info: LANG=en_US.UTF-8 LOGNAME=Administrator LOGONSERVER= GLIM-WIN2K12-1 MAIL=/var/spool/mail//Administrator MANPATH=/usr/local/man:/usr/share/man:/usr/man::/usr/ssl/man OLDPWD=/home/Administrator OS=Windows_NT PATH=/usr/local/bin:/usr/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/bin:/blah/:/cygdrive/c/Program Files/Java/jdk1.7.0_17/bin/ PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC PRINTER=Microsoft XPS Document Writer PROGRAMFILES=C:\Program Files (x86) PS1=[\e]0;\w\a]\n[\e[32m]\u@\h [\e[33m]\w[\e[0m]\n\$ PWD=/home/Administrator SHELL=/bin/bash SHLVL=1 SSH_CLIENT=10.20.76.6 55831 22 SSH_CONNECTION=10.20.76.6 55831 10.14.210.91 22 SSH_TTY=/dev/pty1 SYSTEMDRIVE=C: SYSTEMROOT=C:\Windows temp= TEMP=/tmp TERM=xterm tmp= TMP=/tmp TZ=Etc/GMT USER=Administrator USERDOMAIN=GLIM-WIN2K12-1 USERNAME=Administrator USERPROFILE=C:\Users\Administrator WINDIR=C:\Windows
          Show
          kohsuke Kohsuke Kawaguchi added a comment - This is how SSH behaves. See https://wiki.jenkins-ci.org/display/JENKINS/SSH+Slaves+plugin#SSHSlavesplugin-Loginprofilefiles
          Hide
          guysoft Guy Sheffer added a comment -

          Last comment was a "bug report hijack"! Note that in my inital report CRITICAL environment variables such as PWD and USER are missing. A shell, including a non-interactive one can't issue any call in that state.

          Show
          guysoft Guy Sheffer added a comment - Last comment was a "bug report hijack"! Note that in my inital report CRITICAL environment variables such as PWD and USER are missing. A shell, including a non-interactive one can't issue any call in that state.
          Hide
          dborin David Borin added a comment -

          @Guy Sheffer – apologies if you think my comment is a hijack.

          @Kohsuke – Regardless of interactive or non-interactive, in standard *nix environments, certain env files are read (.profile, .bash_profile). The plugin is much less effective if Jenkins doesn't honor standard *nix conventions. Unsure how this isn't a bug, my "hijack" notwithstanding. I think that the two reports are related.

          Show
          dborin David Borin added a comment - @Guy Sheffer – apologies if you think my comment is a hijack. @Kohsuke – Regardless of interactive or non-interactive, in standard *nix environments, certain env files are read (.profile, .bash_profile). The plugin is much less effective if Jenkins doesn't honor standard *nix conventions. Unsure how this isn't a bug, my "hijack" notwithstanding. I think that the two reports are related.
          Hide
          guysoft Guy Sheffer added a comment -

          David, your comments are not regarding the original issue, please open a new one.

          Show
          guysoft Guy Sheffer added a comment - David, your comments are not regarding the original issue, please open a new one.
          Hide
          billsegall Bill Segall added a comment -

          What solved this for me was running cyglsa-config and rebooting.
          Bill.

          Show
          billsegall Bill Segall added a comment - What solved this for me was running cyglsa-config and rebooting. Bill.

            People

            Assignee:
            ifernandezcalvo Ivan Fernandez Calvo
            Reporter:
            guysoft Guy Sheffer
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: