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

Unable to add to variable that is set before the build is executed. Produces OOM exception

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Duplicate
    • Component/s: envinject-plugin
    • Labels:
      None
    • Environment:
      Windows XP
    • Similar Issues:

      Description

      I am trying to add to an variable that is already in Jenkins.If i have the following entry in my properties file.
      PATH = C:\PROGRAM\BIN;$PATH

      and i check the injectedEnvVars.txt file i see that PATH is set to this

      PATH=C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;

      and so on. IT could be 1000 C:\PROGRAM\BIN; printed in the file making the jenkins build run out of memory.

      I had a look at the code and it might be where the file is being read. IT might be looping around. This can happen with any variable just not PATH.

      This will produce the problem also. There is a loop some where that adds the variable to the variable over and over.
      OS=Windows_NT;$OS

      This is the exception that is produced by Jenkins.

      Archiving artifacts
      FATAL: Java heap space
      java.lang.OutOfMemoryError: Java heap space
      at java.util.Arrays.copyOf(Arrays.java:2894)
      at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:117)
      at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:407)
      at java.lang.StringBuilder.append(StringBuilder.java:136)
      at hudson.Util.replaceMacro(Util.java:160)
      at hudson.Util.replaceMacro(Util.java:127)
      at org.jenkinsci.plugins.envinject.service.EnvInjectEnvVars.resolveVars(EnvInjectEnvVars.java:206)
      at org.jenkinsci.plugins.envinject.EnvInjectListener$2.buildEnvVars(EnvInjectListener.java:211)
      at hudson.model.AbstractBuild.getEnvironment(AbstractBuild.java:942)
      at hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:136)
      at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
      at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:804)
      at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:776)
      at hudson.model.Build$BuildExecution.post2(Build.java:183)
      at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:726)
      at hudson.model.Run.execute(Run.java:1628)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
      at hudson.model.ResourceController.execute(ResourceController.java:88)
      at hudson.model.Executor.run(Executor.java:247)

        Attachments

          Issue Links

            Activity

            Hide
            martin_naughton martin naughton added a comment -

            problem could be here where it is getting the variables from the file. EnvInjectEnvVars.java

            public Map<String, String> getEnvVarsFileProperty(FilePath rootPath,
            EnvInjectLogger logger,
            String propertiesFilePath,
            Map<String, String> propertiesContent,
            Map<String, String> currentEnvVars) throws EnvInjectException {
            Map<String, String> resultMap = new LinkedHashMap<String, String>();
            try

            { resultMap.putAll(rootPath.act(new PropertiesVariablesRetriever(propertiesFilePath, propertiesContent, currentEnvVars, logger))); }

            catch (IOException e)

            { throw new EnvInjectException(e); } catch (InterruptedException e) { throw new EnvInjectException(e); }

            return resultMap;
            }

            Show
            martin_naughton martin naughton added a comment - problem could be here where it is getting the variables from the file. EnvInjectEnvVars.java public Map<String, String> getEnvVarsFileProperty(FilePath rootPath, EnvInjectLogger logger, String propertiesFilePath, Map<String, String> propertiesContent, Map<String, String> currentEnvVars) throws EnvInjectException { Map<String, String> resultMap = new LinkedHashMap<String, String>(); try { resultMap.putAll(rootPath.act(new PropertiesVariablesRetriever(propertiesFilePath, propertiesContent, currentEnvVars, logger))); } catch (IOException e) { throw new EnvInjectException(e); } catch (InterruptedException e) { throw new EnvInjectException(e); } return resultMap; }
            Hide
            martin_naughton martin naughton added a comment -

            Actually from looking at the code the variables are red in like this

            PATH = C:\PROGRAM\BIN;$PATH

            It is the interpretation of the variables is where the problem is.

            Looked at the map returned from the this method that read the properties file and returned the above.
            PropertiesLoader.getVarsFromPropertiesFile(File, Map<String, String>)

            Show
            martin_naughton martin naughton added a comment - Actually from looking at the code the variables are red in like this PATH = C:\PROGRAM\BIN;$PATH It is the interpretation of the variables is where the problem is. Looked at the map returned from the this method that read the properties file and returned the above. PropertiesLoader.getVarsFromPropertiesFile(File, Map<String, String>)
            Hide
            martin_naughton martin naughton added a comment -

            I think i found the reason.

            The PATH (upper case) variable has not been set before the properties file was read. User thinks they are adding to an already defined variable. IF it is not defined then when interpreting the variable it is recursively being added to
            PATH = C:\PROGRAM\BIN;$PATH

            will produce this until the memory runs out
            PATH=C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;

            This Path(lowercase) variable does not a problem because $Path was set before the properties file was read so you just adding to the variable just like on a bash command line.
            Path=C:\PROGRAM\BIN;$Path

            Show
            martin_naughton martin naughton added a comment - I think i found the reason. The PATH (upper case) variable has not been set before the properties file was read. User thinks they are adding to an already defined variable. IF it is not defined then when interpreting the variable it is recursively being added to PATH = C:\PROGRAM\BIN;$PATH will produce this until the memory runs out PATH=C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN;C:\PROGRAM\BIN; This Path(lowercase) variable does not a problem because $Path was set before the properties file was read so you just adding to the variable just like on a bash command line. Path=C:\PROGRAM\BIN;$Path
            Hide
            martin_naughton martin naughton added a comment -

            not sure if you want to fix this. maybe the output should be
            PATH = C:\PROGRAM\BIN;$PATH

            since PATH is not defined and you can not add to it.

            Show
            martin_naughton martin naughton added a comment - not sure if you want to fix this. maybe the output should be PATH = C:\PROGRAM\BIN;$PATH since PATH is not defined and you can not add to it.
            Hide
            janbackhaus Jan Backhaus added a comment -

            today we ran into the same issue under linux
            1.625.2, environment injector plugin 1.92.1

            Show
            janbackhaus Jan Backhaus added a comment - today we ran into the same issue under linux 1.625.2, environment injector plugin 1.92.1
            Hide
            oleg_nenashev Oleg Nenashev added a comment -

            Fix for JENKINS-30467 should likely solve this issue.
            To be released in 1.93

            Show
            oleg_nenashev Oleg Nenashev added a comment - Fix for JENKINS-30467 should likely solve this issue. To be released in 1.93

              People

              • Assignee:
                gbois Gregory Boissinot
                Reporter:
                martin_naughton martin naughton
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: