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

Variable injected with EnvInject not supported

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      It looks like variables injected with EnvInject plugin are not resolved by the rich-text-publisher

        Attachments

          Activity

          Hide
          xtof christophe dehaudt added a comment -

          I'm facing the same problem

          trying to do such things like :
          ${FILE:${ENV:INSTALL_DIR}/Success.html}

          => the result is : I see that the env variable is resolved but not the file

          did a bit of digging, i believe the problem is here
          RichTextPublisher.java (line 165)

          Matcher matcher = FILE_VAR_PATTERN.matcher(text);
          int start = 0;
          while (matcher.find(start)) {
          String fileName = matcher.group(2); <----- HERE
          FilePath filePath = new FilePath(build.getWorkspace(), fileName);
          if (filePath.exists()) {
          String value = filePath.readToString();
          if (matcher.group(1).length() != 4)

          { // Group is file_sl value = value.replace("\n", "").replace("\r", ""); }

          vars.put(String.format("%s:%s", matcher.group(1), fileName), value);
          }
          start = matcher.end();
          }

          can we do something like

          String fileName = replaceVars(matcher.group(2), vars);

          that might do the job, no?

          Show
          xtof christophe dehaudt added a comment - I'm facing the same problem trying to do such things like : ${FILE:${ENV:INSTALL_DIR}/Success.html} => the result is : I see that the env variable is resolved but not the file did a bit of digging, i believe the problem is here RichTextPublisher.java (line 165) Matcher matcher = FILE_VAR_PATTERN.matcher(text); int start = 0; while (matcher.find(start)) { String fileName = matcher.group(2); <----- HERE FilePath filePath = new FilePath(build.getWorkspace(), fileName); if (filePath.exists()) { String value = filePath.readToString(); if (matcher.group(1).length() != 4) { // Group is file_sl value = value.replace("\n", "").replace("\r", ""); } vars.put(String.format("%s:%s", matcher.group(1), fileName), value); } start = matcher.end(); } can we do something like String fileName = replaceVars(matcher.group(2), vars); that might do the job, no?
          Hide
          masterhard Dmitry Korotkov added a comment -

          The proposed change will not help. For the specified example:

          ${FILE:${ENV:INSTALL_DIR}/Success.html}

          Captured group will be ${ENV:INSTALL_DIR which will not be parsed by replaceVars as you expect.

          I see the support for nested expressions as a bad idea - it would be even possible to run into endless recursion if it is not done right.

          What do you think if we allow constructs like:

          ${FILE:ENV:SOMEVAR}

          which will be resolved into file content of the specified file?

          Show
          masterhard Dmitry Korotkov added a comment - The proposed change will not help. For the specified example: ${FILE:${ENV:INSTALL_DIR}/Success.html} Captured group will be ${ENV:INSTALL_DIR which will not be parsed by replaceVars as you expect. I see the support for nested expressions as a bad idea - it would be even possible to run into endless recursion if it is not done right. What do you think if we allow constructs like: ${FILE:ENV:SOMEVAR } which will be resolved into file content of the specified file?
          Hide
          oleg_nenashev Oleg Nenashev added a comment -

          @Dmitry
          I think you should consider the usage of Token Macro Plugin

          Show
          oleg_nenashev Oleg Nenashev added a comment - @Dmitry I think you should consider the usage of Token Macro Plugin

            People

            Assignee:
            masterhard Dmitry Korotkov
            Reporter:
            herv herve martin
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated: