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

Some env variables can not be used to inject, for example $NODE_NAME

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: envinject-plugin
    • Labels:
      None
    • Environment:
      master or slave node without special settings
    • Similar Issues:

      Description

      This simple injection fails:
      cfgLocation="--env-cfg=${HOME}/${NODE_NAME}"

      It seems that envinject only uses a subset of the environment variables available at the time of evaluating. In contrast, testing the same using a Shell execution works as expected:

      env
      cfgLocation="--env-cfg=${HOME}/${NODE_NAME}"
      echo "manually set[${cfgLocation}]"

      The full output of both (uninteresting things omitted) is shown here:

      Started by user ....
      Building on master
      [EnvInject] - Injecting as environment variables the properties content
      'cfgLocation="--env-cfg=/var/lib/jenkins/${NODE_NAME}"
      '

      [EnvInject] - Unset unresolved 'cfgLocation' variable.
      [envinject test] $ /bin/sh -xe /tmp/hudson9116632610853382727.sh
      + env
      JENKINS_HOME=/var/lib/jenkins
      USER=jenkins
      MAIL=/var/mail/jenkins
      LD_LIBRARY_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk/jre/lib/i386:/usr/lib/jvm/java-6-openjdk/jre/../lib/i386
      HUDSON_URL=http://example.org/
      NODE_LABELS=master
      SHLVL=1
      HOME=/var/lib/jenkins
      WORKSPACE=/var/lib/jenkins/workspace/envinject test
      NODE_NAME=master
      LOGNAME=jenkins
      _=/usr/bin/daemon
      EXECUTOR_NUMBER=0
      TERM=xterm
      HUDSON_HOME=/var/lib/jenkins
      PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
      BUILD_ID=2011-11-03_12-37-03
      BUILD_TAG=jenkins-envinject test-4
      LANG=en_US.UTF-8
      BUILD_NUMBER=4
      SHELL=/bin/bash
      JOB_NAME=envinject test
      PWD=/var/lib/jenkins/workspace/envinject test
      + cfgLocation=--env-cfg=/var/lib/jenkins/master
      + echo manually set[--env-cfg=/var/lib/jenkins/master]
      manually set[--env-cfg=/var/lib/jenkins/master]
      Finished: SUCCESS

        Attachments

          Activity

          Hide
          gbois Gregory Boissinot added a comment -

          You have to check 'Keep Jenkins Environment Variables'

          Show
          gbois Gregory Boissinot added a comment - You have to check 'Keep Jenkins Environment Variables'
          Hide
          marcelhuber Marcel Huber added a comment -

          On Main node and slave nodes, I enabled the following without any effect on the NODE_NAME variable

          ...
          Global settings
          x Prepare jobs environment (checked)
          Unset System Environment Variables _ (unchecked)
          ...

          I restarted master and slave nodes but could not see a different result. I also tried to set a global variable and looking it up but without success. Again, a lookup from within a Shell script worked perfectly.

          btw: I am using Jenkins 1.437 and EnvInject 0.21

          Show
          marcelhuber Marcel Huber added a comment - On Main node and slave nodes, I enabled the following without any effect on the NODE_NAME variable ... Global settings x Prepare jobs environment (checked) Unset System Environment Variables _ (unchecked) ... I restarted master and slave nodes but could not see a different result. I also tried to set a global variable and looking it up but without success. Again, a lookup from within a Shell script worked perfectly. btw: I am using Jenkins 1.437 and EnvInject 0.21
          Hide
          gbois Gregory Boissinot added a comment -

          I'm afraid I can't reproduce your problem.
          Your job runs on a slave.
          The settings is configured at node level and not at master level.
          Could you verify that you have unchecked 'Unset System Environment Variables '?
          Additionnally, could you attach your job configuration file (config.xml)?

          Show
          gbois Gregory Boissinot added a comment - I'm afraid I can't reproduce your problem. Your job runs on a slave. The settings is configured at node level and not at master level. Could you verify that you have unchecked 'Unset System Environment Variables '? Additionnally, could you attach your job configuration file (config.xml)?
          Hide
          marcelhuber Marcel Huber added a comment -

          configuration files requested

          Show
          marcelhuber Marcel Huber added a comment - configuration files requested
          Hide
          marcelhuber Marcel Huber added a comment -

          I checked in the config file and every slave and also the master contains a node properties setting for envinject to unset the system variables. See the main config file attached (stripped some fqdn's and key things) and the test job configuration.
          To eliminate master/slave based errors, I tested on the master node itself but having the same non-working effect.

          Show
          marcelhuber Marcel Huber added a comment - I checked in the config file and every slave and also the master contains a node properties setting for envinject to unset the system variables. See the main config file attached (stripped some fqdn's and key things) and the test job configuration. To eliminate master/slave based errors, I tested on the master node itself but having the same non-working effect.
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Gregory Boissinot
          Path:
          src/main/java/org/jenkinsci/plugins/envinject/EnvInjectBuildWrapper.java
          src/main/java/org/jenkinsci/plugins/envinject/EnvInjectBuilder.java
          src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java
          src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectActionSetter.java
          src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectEnvVars.java
          src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectVariableGetter.java
          http://jenkins-ci.org/commit/envinject-plugin/91a47fb9c3a5bcb85003472c87eef4a90f7105ab
          Log:
          Fixed JENKINS-11595

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Gregory Boissinot Path: src/main/java/org/jenkinsci/plugins/envinject/EnvInjectBuildWrapper.java src/main/java/org/jenkinsci/plugins/envinject/EnvInjectBuilder.java src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectActionSetter.java src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectEnvVars.java src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectVariableGetter.java http://jenkins-ci.org/commit/envinject-plugin/91a47fb9c3a5bcb85003472c87eef4a90f7105ab Log: Fixed JENKINS-11595
          Hide
          gbois Gregory Boissinot added a comment -

          Thanks for your inputs.
          Fixed in 0.23

          Show
          gbois Gregory Boissinot added a comment - Thanks for your inputs. Fixed in 0.23
          Hide
          marcelhuber Marcel Huber added a comment -

          It works!
          Thanks a lot.

          Show
          marcelhuber Marcel Huber added a comment - It works! Thanks a lot.

            People

            • Assignee:
              gbois Gregory Boissinot
              Reporter:
              marcelhuber Marcel Huber
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: