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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved (View Workflow)
    • Minor
    • Resolution: Fixed
    • core
    • None

    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

            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.

            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.

            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?

            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?
            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()?

            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()?
            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.

            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.
            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. =)

            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. =)

            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.

            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.
            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
            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

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

              Dates

                Created:
                Updated:
                Resolved: