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

Using node properties env vars in email-ext plugin

    • Icon: Patch Patch
    • Resolution: Fixed
    • Icon: Major Major
    • email-ext-plugin
    • None
    • any

      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.

          [JENKINS-5465] Using node properties env vars in email-ext plugin

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

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

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

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

              Created:
              Updated:
              Resolved: