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

Using node properties env vars in email-ext plugin

    Details

    • Similar Issues:

      Description

      I had the need to be able to use the node properties env vars in the plugin email-ext.
      So for example we needed to build the same project on a different hardware and OS.
      Like Solaris SPARC, AIX, HPUX, Windows and so on.
      So in the node properties env vars we set variables for identifying which is the computer and the OS version/platform and others.
      Those environment variables we needed to use in the email-ext plugin so we can know which project was build successful or failed or any other problems.
      Also similar use for svn-tag plugin and scp plugin for which I will create another issues.
      Here is the code changes I made to work as I needed:
      The changes was only in class /email-ext-2.5-sources/hudson/plugins/emailext/plugins/ContentBuilder.java

      I added a method:
      /**

      • Returns the environment variables set for a node/slave. So you can use
      • them, as are in your environment
      • @param envVars
      • @return
        */
        public static EnvVars getEnvVars() {
        Node node = Computer.currentComputer().getNode();
        DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node
        .getNodeProperties();

      if (Computer.currentComputer() instanceof MasterComputer)

      { Hudson instance = Hudson.getInstance(); nodeProperties=instance.getGlobalNodeProperties(); }

      Iterator<NodeProperty<?>> iterator = nodeProperties.iterator();
      while (iterator.hasNext()) {
      NodeProperty<?> next = iterator.next();
      if (next instanceof EnvironmentVariablesNodeProperty)

      { EnvironmentVariablesNodeProperty envVarProp = (EnvironmentVariablesNodeProperty) next; EnvVars envVars = envVarProp.getEnvVars(); return envVars; }

      }
      return null;
      }

      and changed the method transformText to be like this:
      public <P extends AbstractProject<P, B>, B extends AbstractBuild<P, B>>
      String transformText(String origText, ExtendedEmailPublisher publisher, EmailType type, B build) {
      String newText = origText.replaceAll(PROJECT_DEFAULT_BODY, Matcher.quoteReplacement(publisher.defaultContent))
      .replaceAll(PROJECT_DEFAULT_SUBJECT, Matcher.quoteReplacement(publisher.defaultSubject))
      .replaceAll(DEFAULT_BODY, Matcher.quoteReplacement(ExtendedEmailPublisher.DESCRIPTOR.getDefaultBody()))
      .replaceAll(DEFAULT_SUBJECT, Matcher.quoteReplacement(ExtendedEmailPublisher.DESCRIPTOR.getDefaultSubject()));

      newText = replaceTokensWithContent(newText, publisher, type, build);

      EnvVars objNodeEnvVars = getEnvVars();
      if (objNodeEnvVars != null)

      { newText=hudson.Util.replaceMacro(newText, objNodeEnvVars); }

      return newText;
      }

      I hope you will add this improvement to the plugin(s).
      Also this EnvironmentVariablesNodeProperty object could be used in a custom BuildWrapper to set the environment variables into the EnvironmentVariablesNodeProperty object so can be accessed later in this plugins I mentioned.

        Attachments

          Activity

          kostakostadinov kostakostadinov created issue -
          mindless Alan Harder made changes -
          Field Original Value New Value
          Summary Please add the improvement I already did. For using node properties env vars in the plugin Using node properties env vars in email-ext plugin
          Issue Type Improvement [ 4 ] Patch [ 5 ]
          Hide
          krwalker krwalker added a comment -

          I believe this issue could be resolved if JENKINS-5925 (build.getEnvironment(...) does not include the node environment settings) was resolved .

          I do have a patch inspired by the code in the description above which modifies EnvContent.java with a workaround. Would it be appropriate to commit this change?

          Show
          krwalker krwalker added a comment - I believe this issue could be resolved if JENKINS-5925 (build.getEnvironment(...) does not include the node environment settings) was resolved . I do have a patch inspired by the code in the description above which modifies EnvContent.java with a workaround. Would it be appropriate to commit this change?
          krwalker krwalker made changes -
          Assignee krwalker [ krwalker ]
          krwalker krwalker made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in hudson
          User: : krwalker
          Path:
          trunk/hudson/plugins/email-ext/pom.xml
          trunk/hudson/plugins/email-ext/src/main/java/hudson/plugins/emailext/plugins/content/EnvContent.java
          trunk/hudson/plugins/email-ext/src/test/java/hudson/plugins/emailext/plugins/content/EnvContentTest.java
          http://jenkins-ci.org/commit/29857
          Log:
          [FIXED JENKINS-5465] Added an EnvironmentContributingAction temporarily to the build so that build.getEnvironment() will contain the node environment properties.

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in hudson User: : krwalker Path: trunk/hudson/plugins/email-ext/pom.xml trunk/hudson/plugins/email-ext/src/main/java/hudson/plugins/emailext/plugins/content/EnvContent.java trunk/hudson/plugins/email-ext/src/test/java/hudson/plugins/emailext/plugins/content/EnvContentTest.java http://jenkins-ci.org/commit/29857 Log: [FIXED JENKINS-5465] Added an EnvironmentContributingAction temporarily to the build so that build.getEnvironment() will contain the node environment properties.
          scm_issue_link SCM/JIRA link daemon made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in hudson
          User: : krwalker
          Path:
          trunk/hudson/plugins/email-ext/pom.xml
          trunk/hudson/plugins/email-ext/src/main/java/hudson/plugins/emailext/plugins/content/EnvContent.java
          trunk/hudson/plugins/email-ext/src/test/java/hudson/plugins/emailext/plugins/content/EnvContentTest.java
          http://jenkins-ci.org/commit/29857
          Log:
          [FIXED JENKINS-5465] Added an EnvironmentContributingAction temporarily to the build so that build.getEnvironment() will contain the node environment properties.

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in hudson User: : krwalker Path: trunk/hudson/plugins/email-ext/pom.xml trunk/hudson/plugins/email-ext/src/main/java/hudson/plugins/emailext/plugins/content/EnvContent.java trunk/hudson/plugins/email-ext/src/test/java/hudson/plugins/emailext/plugins/content/EnvContentTest.java http://jenkins-ci.org/commit/29857 Log: [FIXED JENKINS-5465] Added an EnvironmentContributingAction temporarily to the build so that build.getEnvironment() will contain the node environment properties.
          abayer Andrew Bayer made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          rtyler R. Tyler Croy made changes -
          Workflow JNJira [ 135554 ] JNJira + In-Review [ 203547 ]

            People

            • Assignee:
              krwalker krwalker
              Reporter:
              kostakostadinov kostakostadinov
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: