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

Using node properties env vars in email-ext plugin

XMLWordPrintable

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

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

              Created:
              Updated:
              Resolved: