• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • envinject-plugin
    • None

      Update to global variable aren't applied to jobs when envinject plugin is installed

      how to reproduce :
      running fresh 1.494, with a single Job to echo $FOO
      FOO global variable set to "foo"

      build #1 :
      echo foo

      change FOO to set value = "bar"

      build #2 :
      echo bar

      Right, then install envinject (1.78), restart

      build #3 :
      echo bar

      change FOO to set value = "qix"

      build #2 :
      echo bar

      wtf ?

          [JENKINS-16316] global variable not updated

          The following workaround fixed it for me:

          On main jenkins config page, turn on the option "Prepare jobs environment" and unselect "Unset System Environment Variables"
          Save Config and restart the slave.

          Geoff Cummings added a comment - The following workaround fixed it for me: On main jenkins config page, turn on the option "Prepare jobs environment" and unselect "Unset System Environment Variables" Save Config and restart the slave.

          I think it is related to the following code in EnvironmentVariablesNodeLoader:

          for (NodeProperty<?> nodeProperty : Hudson.getInstance().getGlobalNodeProperties()) {
              if (nodeProperty instanceof EnvironmentVariablesNodeProperty) {
                  EnvironmentVariablesNodeProperty variablesNodeProperty = (EnvironmentVariablesNodeProperty) nodeProperty;
                  EnvVars envVars = variablesNodeProperty.getEnvVars();
                  EnvInjectEnvVars envInjectEnvVars = new EnvInjectEnvVars(logger);
                  configNodeEnvVars.putAll(envVars);
                  envInjectEnvVars.resolveVars(configNodeEnvVars, nodeEnvVars);
              }
          }
          

          Without the "Prepare jobs environment" checked, the if statement above resolves to false so env vars are not updated.... i think.

          Geoff Cummings added a comment - I think it is related to the following code in EnvironmentVariablesNodeLoader: for (NodeProperty<?> nodeProperty : Hudson.getInstance().getGlobalNodeProperties()) { if (nodeProperty instanceof EnvironmentVariablesNodeProperty) { EnvironmentVariablesNodeProperty variablesNodeProperty = (EnvironmentVariablesNodeProperty) nodeProperty; EnvVars envVars = variablesNodeProperty.getEnvVars(); EnvInjectEnvVars envInjectEnvVars = new EnvInjectEnvVars(logger); configNodeEnvVars.putAll(envVars); envInjectEnvVars.resolveVars(configNodeEnvVars, nodeEnvVars); } } Without the "Prepare jobs environment" checked, the if statement above resolves to false so env vars are not updated.... i think.

          That workaround doesn't seem to work for me however.

          Walter Kacynski added a comment - That workaround doesn't seem to work for me however.

          Jesse Glick added a comment -

          I filed a new pull request to fix this.

          Upgrading priority since this bug breaks basic Jenkins functionality merely by installing a plugin, so it is far from obvious to a user where to start diagnosis.

          Jesse Glick added a comment - I filed a new pull request to fix this. Upgrading priority since this bug breaks basic Jenkins functionality merely by installing a plugin, so it is far from obvious to a user where to start diagnosis.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/java/org/jenkinsci/plugins/envinject/EnvInjectComputerListener.java
          http://jenkins-ci.org/commit/envinject-plugin/dedee1978345fa23e7d3773f64572c4a6f027882
          Log:
          [FIXED JENKINS-16316] Do not inject master node property variables into EnvVars.masterEnvVars on slaves.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/java/org/jenkinsci/plugins/envinject/EnvInjectComputerListener.java http://jenkins-ci.org/commit/envinject-plugin/dedee1978345fa23e7d3773f64572c4a6f027882 Log: [FIXED JENKINS-16316] Do not inject master node property variables into EnvVars.masterEnvVars on slaves.

          Code changed in jenkins
          User: Gregory Boissinot
          Path:
          src/main/java/org/jenkinsci/plugins/envinject/EnvInjectComputerListener.java
          http://jenkins-ci.org/commit/envinject-plugin/3371ed7601431b57780a30ddea4b84dd27e38b6e
          Log:
          Merge pull request #20 from jglick/sticky-var-JENKINS-16316

          JENKINS-16316 Changes to global variables not honored.

          Compare: https://github.com/jenkinsci/envinject-plugin/compare/b5cc29fc9695...3371ed760143

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Gregory Boissinot Path: src/main/java/org/jenkinsci/plugins/envinject/EnvInjectComputerListener.java http://jenkins-ci.org/commit/envinject-plugin/3371ed7601431b57780a30ddea4b84dd27e38b6e Log: Merge pull request #20 from jglick/sticky-var- JENKINS-16316 JENKINS-16316 Changes to global variables not honored. Compare: https://github.com/jenkinsci/envinject-plugin/compare/b5cc29fc9695...3371ed760143

          Upgrading to 1.88 has fixed the problem for me as well.

          Walter Kacynski added a comment - Upgrading to 1.88 has fixed the problem for me as well.

          Guy Shaanan added a comment -

          Not sure if it is the same bug or a new one:
          When you have a build parameter, and you try to inject a value to it, the value is not injected.

          Ways to reproduce:
          JOB #1
          ----------
          1. Add build parameter called BRANCH (or whatever name you like)
          2. Add shell script with echo "BRANCH=test" > build.prop
          3. Inject build.prop using the envinject plugin
          4. echo ${BRANCH}
          >> this echos blank value (or the default value set to parameter) instead of "test"

          JOB #2
          -----------
          1. remove the parameter named BRANCH.
          Rest of the steps (2-4) remain the same:
          2. Add shell script with echo "BRANCH=test" > build.prop
          3. Inject build.prop using the envinject plugin
          4. echo ${BRANCH}
          >> this echos "test"

          We've upgraded Jenkins to 1.584 and envinject plugin to 1.90 and this behavior happens.

          Job #1 and Job #2 should both echo "test" to the screen.

          This was working before the upgrade we did (I don't remember which plugin version we had previously).

          Thanks.

          Guy Shaanan added a comment - Not sure if it is the same bug or a new one: When you have a build parameter, and you try to inject a value to it, the value is not injected. Ways to reproduce: JOB #1 ---------- 1. Add build parameter called BRANCH (or whatever name you like) 2. Add shell script with echo "BRANCH=test" > build.prop 3. Inject build.prop using the envinject plugin 4. echo ${BRANCH} >> this echos blank value (or the default value set to parameter) instead of "test" JOB #2 ----------- 1. remove the parameter named BRANCH. Rest of the steps (2-4) remain the same: 2. Add shell script with echo "BRANCH=test" > build.prop 3. Inject build.prop using the envinject plugin 4. echo ${BRANCH} >> this echos "test" We've upgraded Jenkins to 1.584 and envinject plugin to 1.90 and this behavior happens. Job #1 and Job #2 should both echo "test" to the screen. This was working before the upgrade we did (I don't remember which plugin version we had previously). Thanks.

          Jesse Glick added a comment -

          guyshaanan:

          Not sure if it is the same bug or a new one

          Then file a new bug report, and link it to this one as possibly related.

          Jesse Glick added a comment - guyshaanan : Not sure if it is the same bug or a new one Then file a new bug report, and link it to this one as possibly related.

          Bikram Bora added a comment -

          Issue still occuring on 1.92.1

          Had to revert to 1.88 to get it working

          Seems like there is a toss up between ->
          1. people using it on master (like me to inject variables during a build)
          2. people using it on nodes to set up the environment at the beginning.

          When one feature works the other seems to fail

          for usage 1 -> 1.88 works perfectly
          for usage 2 -> 1.92.1 seems to work

          Maybe fork the plugin into two separate plugins

          Bikram Bora added a comment - Issue still occuring on 1.92.1 Had to revert to 1.88 to get it working Seems like there is a toss up between -> 1. people using it on master (like me to inject variables during a build) 2. people using it on nodes to set up the environment at the beginning. When one feature works the other seems to fail for usage 1 -> 1.88 works perfectly for usage 2 -> 1.92.1 seems to work Maybe fork the plugin into two separate plugins

            Unassigned Unassigned
            ndeloof Nicolas De Loof
            Votes:
            4 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: