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 ]
          krwalker krwalker made changes -
          Assignee krwalker [ krwalker ]
          krwalker krwalker made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          scm_issue_link SCM/JIRA link daemon made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          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: