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

Environment variables are not set in init script

    Details

    • Similar Issues:

      Description

      It looks like init-scripts don't get the environment variables defined for a node, or global environment variables defined in the main Configure Jenkins page, injected. At least for EC2 nodes.

      The environment variables are present when running jobs, but not when running init scripts. Even when those environment variables are shown in the "Enviroment Variables" list under "System Information" for a node, an init script that has a line like:

      env > /tmp/init-environ
      

      will print an environment that doesn't include them, and shell substitutions won't use them.

      In case they were set but not exported I tested with:

      set > /tmp/set-environ
      

      but the vars weren't present there either.

      This makes it harder to parameterize init scripts.

      The environment that was set was:

      SHELL=/bin/bash
      TERM=dumb
      USER=root
      SUDO_USER=admin
      SUDO_UID=1000
      USERNAME=root
      MAIL=/var/mail/root
      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
      PWD=/home/admin
      SHLVL=1
      SUDO_COMMAND=/tmp/init.sh
      HOME=/root
      LOGNAME=root
      SUDO_GID=1000
      _=/usr/bin/env
      

        Attachments

          Activity

          Hide
          ringerc Craig Ringer added a comment - - edited

          It looks like initScript execution is done by ssh/EC2UnixLauncher.java in launch(...).

          So we'd need to inject slave and global environment variables on the remote end of the SSH call there.

          The Trilead ssh wrapper doesn't seem to support setting env vars, so the simplest option would be to prepend them to the init script.

          I could add that part fairly trivially. My problem is that I have no idea how to get the environment variables configured on a node, or get the global environment vars from the Jenkins configuration.

          Show
          ringerc Craig Ringer added a comment - - edited It looks like initScript execution is done by ssh/EC2UnixLauncher.java in launch(...). So we'd need to inject slave and global environment variables on the remote end of the SSH call there. The Trilead ssh wrapper doesn't seem to support setting env vars, so the simplest option would be to prepend them to the init script. I could add that part fairly trivially. My problem is that I have no idea how to get the environment variables configured on a node, or get the global environment vars from the Jenkins configuration.
          Hide
          ringerc Craig Ringer added a comment - - edited

          It looks like the best solution might be to use hudson.Launcher on a VirtualChannel set up by the ec2-plugin and use hudson.EnvVars .

          I think that might make Windows command launching work too, though that's not much good if the slave agent can't be started.

          Show
          ringerc Craig Ringer added a comment - - edited It looks like the best solution might be to use hudson.Launcher on a VirtualChannel set up by the ec2-plugin and use hudson.EnvVars . I think that might make Windows command launching work too, though that's not much good if the slave agent can't be started.
          Hide
          ringerc Craig Ringer added a comment -

          Implementation note: a useful reference for environment variable setting is `core/src/main/java/hudson/tasks/CommandInterpreter.java`

          Show
          ringerc Craig Ringer added a comment - Implementation note: a useful reference for environment variable setting is `core/src/main/java/hudson/tasks/CommandInterpreter.java`
          Hide
          olvesh Olve Hansen added a comment -

          Is there a workaround for this issue?

          Show
          olvesh Olve Hansen added a comment - Is there a workaround for this issue?

            People

            • Assignee:
              francisu Francis Upton
              Reporter:
              ringerc Craig Ringer
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: