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

build.getEnvironment(...) does not include the node environment settings

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: core
    • Labels:
      None
    • Similar Issues:

      Description

      The email-ext plugin has source that reads:
      getContent(AbstractBuild<P, B> build,...) ... {
      Map<String, String> env = build.getEnvironment(TaskListener.NULL);

      This map does not appear to include environment settings from the node configuration page.

        Attachments

          Issue Links

            Activity

            Hide
            krwalker krwalker added a comment -

            This patch may fix this problem, though I'm not quite sure. Uploading now in case this could help someone else sooner rather than later.

            Show
            krwalker krwalker added a comment - This patch may fix this problem, though I'm not quite sure. Uploading now in case this could help someone else sooner rather than later.
            Hide
            kostakostadinov kostakostadinov added a comment -

            I really like this patch.
            I made changes to a bunch of plugins just to have this env settings accessible.
            I suppose mu patches will be useless if this patch is applied to the Hudson core all the plugins will got this settings.
            Which expands the usefulness of all the plugins.
            Please Mr. Kawaguchi could you apply this patch?

            Show
            kostakostadinov kostakostadinov added a comment - I really like this patch. I made changes to a bunch of plugins just to have this env settings accessible. I suppose mu patches will be useless if this patch is applied to the Hudson core all the plugins will got this settings. Which expands the usefulness of all the plugins. Please Mr. Kawaguchi could you apply this patch?
            Hide
            krwalker krwalker added a comment -

            After further inspection, I no longer believe file attachment 1 (hudson.model.Run.patch) is an appropriate patch for this bug.

            The bug appears to be caused by Build.RunnerImpl setting AbstractBuild.buildEnvironments = null after all the builders are finished. Because of this, none of the Publishers have access to all of the environment from AbstractBuild.getEnvironment().

            Is it necessary to set buildEnvironments = null at all, and if it is, could this be done at the end of Build.RunnerImpl.cleanUp()?

            Is it appropriate for Publishers to call AbstractBuild.getEnvironment()?

            Show
            krwalker krwalker added a comment - After further inspection, I no longer believe file attachment 1 (hudson.model.Run.patch) is an appropriate patch for this bug. The bug appears to be caused by Build.RunnerImpl setting AbstractBuild.buildEnvironments = null after all the builders are finished. Because of this, none of the Publishers have access to all of the environment from AbstractBuild.getEnvironment(). Is it necessary to set buildEnvironments = null at all, and if it is, could this be done at the end of Build.RunnerImpl.cleanUp()? Is it appropriate for Publishers to call AbstractBuild.getEnvironment()?
            Hide
            mindless Alan Harder added a comment -

            I fixed some issues filed against batch-task plugin related to various types of env vars not being present when tasks run, so I hit this problem too. I don't know why those vars are discarded either, but I noted this in a comment in batch_task/BatchRun.java (look for "buildEnvironments are discarded").. you can see the code I used there to get a more complete environment, including node settings and any from "setenv" plugin.

            Show
            mindless Alan Harder added a comment - I fixed some issues filed against batch-task plugin related to various types of env vars not being present when tasks run, so I hit this problem too. I don't know why those vars are discarded either, but I noted this in a comment in batch_task/BatchRun.java (look for "buildEnvironments are discarded").. you can see the code I used there to get a more complete environment, including node settings and any from "setenv" plugin.
            Hide
            abayer Andrew Bayer added a comment -

            In hudson.model.Build.RunnerImpl.doRun (and the equivalent in Maven builds as well), tearDown is called on each of the environments before they're nulled out - as long as that tearDown call is left, it seems like it'd be fine to move the nulling to cleanUp, as suggested. I'll try that now and see if it breaks anything. =)

            Show
            abayer Andrew Bayer added a comment - In hudson.model.Build.RunnerImpl.doRun (and the equivalent in Maven builds as well), tearDown is called on each of the environments before they're nulled out - as long as that tearDown call is left, it seems like it'd be fine to move the nulling to cleanUp, as suggested. I'll try that now and see if it breaks anything. =)
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in hudson
            User: : abayer
            Path:
            trunk/hudson/main/core/src/main/java/hudson/model/Build.java
            trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenBuild.java
            trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java
            http://jenkins-ci.org/commit/34814
            Log:
            JENKINS-5925 Moved nulling out of buildEnvironments to cleanUp, so that node variables are available to Publishers.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in hudson User: : abayer Path: trunk/hudson/main/core/src/main/java/hudson/model/Build.java trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenBuild.java trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java http://jenkins-ci.org/commit/34814 Log: JENKINS-5925 Moved nulling out of buildEnvironments to cleanUp, so that node variables are available to Publishers.
            Hide
            dogfood dogfood added a comment -

            Integrated in hudson_main_trunk #261
            JENKINS-5925 Moved nulling out of buildEnvironments to cleanUp, so that node variables are available to Publishers.

            abayer :
            Files :

            • /trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenBuild.java
            • /trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java
            • /trunk/hudson/main/core/src/main/java/hudson/model/Build.java
            Show
            dogfood dogfood added a comment - Integrated in hudson_main_trunk #261 JENKINS-5925 Moved nulling out of buildEnvironments to cleanUp, so that node variables are available to Publishers. abayer : Files : /trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenBuild.java /trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java /trunk/hudson/main/core/src/main/java/hudson/model/Build.java

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                krwalker krwalker
              • Votes:
                3 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: