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

Variable injected with EnvInject not supported

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

          [JENKINS-21333] Variable injected with EnvInject not supported

          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?

          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?

          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?

          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?

          Oleg Nenashev added a comment -

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

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

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

              Created:
              Updated: