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

withMaven is not picking mavenOpts: '-Xmx2048m'

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I am getting an error "java.lang.OutOfMemoryError: Java heap space" when i am trying to build my code.

      And I am trying to pass JAVA_OPTIONS as below but for some reason it is not being passed.
      stage('Build') { steps { script { withMaven(mavenOpts: '-Xmx2048m')

      { sh("mvn package -DskipTests=true") }

      }
      }
      }
      Could see in the logs as below:
      [withMaven] Options: []
      [withMaven] Available options:
      [withMaven] using JDK installation provided by the build agent
      $ /bin/sh -c "which mvn"
      [withMaven] using Maven installation provided by the build agent with executable /apps/pcehr/tools/apache-maven-3.3.9/bin/mvn
      [Pipeline] {
       

        Attachments

          Activity

          Hide
          boby8064 Sadguru Chikkam added a comment -

          mavenOpts: '-Xmx2048m' is not being passed through withMaven

          Show
          boby8064 Sadguru Chikkam added a comment - mavenOpts: '-Xmx2048m' is not being passed through withMaven
          Hide
          acrespo Andre Crespo added a comment -

          I have something near that. I already have a MAVEN_OPTS global variable set on jenkins (Global Settings) and when I set mavenOpts in withMaven command, the content is appending with the global variable. Is there any way to not append or this is a bug?

          Show
          acrespo Andre Crespo added a comment - I have something near that. I already have a MAVEN_OPTS global variable set on jenkins (Global Settings) and when I set mavenOpts in withMaven command, the content is appending with the global variable. Is there any way to not append or this is a bug?
          Hide
          aheritier Arnaud Héritier added a comment -

          Hi Sadguru Chikkam, Andre Crespo

          Could you give me more details about why you consider that Maven doesn't use the value you are passing ?

          Andre Crespo's feedback is effectively making sense to me when I read the code : https://github.com/jenkinsci/pipeline-maven-plugin/blob/master/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java#L362-L372

          If MAVEN_OPTS is already defined in the environment it is appended to the one configured using withMaven. Maybe we could allow to not reuse it but at the minimum without introducing any additional configuration complexity I think we should append the withMaven content after the existing MAVEN_OPTS content to be sure that the pipeline can override what is already defined globally (on the agent, ..)

          WDYT?

          Show
          aheritier Arnaud Héritier added a comment - Hi Sadguru Chikkam , Andre Crespo Could you give me more details about why you consider that Maven doesn't use the value you are passing ? Andre Crespo 's feedback is effectively making sense to me when I read the code : https://github.com/jenkinsci/pipeline-maven-plugin/blob/master/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java#L362-L372 If MAVEN_OPTS is already defined in the environment it is appended to the one configured using withMaven. Maybe we could allow to not reuse it but at the minimum without introducing any additional configuration complexity I think we should append the withMaven content after the existing MAVEN_OPTS content to be sure that the pipeline can override what is already defined globally (on the agent, ..) WDYT?
          Hide
          acrespo Andre Crespo added a comment -

          I detected this when i echo MAVEN_OPTS inside withMaven block. I have a global MAVEN_OPTS to be used with almost all jobs in jenkins but some projects need specific MAVEN_OPTS to be used with different JDKs.

          After set mavenOpts: '-Xms1g -Xmx1g -XX:MaxPermSize=512m -XX:PermSize=512m -Xss16m -XX:TieredStopAtLevel=1 -XX:+UseG1GC -XX:+OptimizeStringConcat -XX:+UseStringCache -XX:+AggressiveOpts -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=25 -XX:G1MaxNewSizePercent=30 -XX:ParallelGCThreads=10 -XX:ConcGCThreads=3 -XX:InitiatingHeapOccupancyPercent=40', I did an echo in MAVEN_OPTS and it return above settings plus global MAVEN_OPTS (at this order).

          This is not occuring when set JVM Options on freestyle projects. the maven options is always what I set in the job. If you want to mantain this way on pipeline version maybe a option to overwrite global MAVEN_OPTS (true or false) is the best.

           

          Show
          acrespo Andre Crespo added a comment - I detected this when i echo MAVEN_OPTS inside withMaven block. I have a global MAVEN_OPTS to be used with almost all jobs in jenkins but some projects need specific MAVEN_OPTS to be used with different JDKs. After set mavenOpts: '-Xms1g -Xmx1g -XX:MaxPermSize=512m -XX:PermSize=512m -Xss16m -XX:TieredStopAtLevel=1 -XX:+UseG1GC -XX:+OptimizeStringConcat -XX:+UseStringCache -XX:+AggressiveOpts -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=25 -XX:G1MaxNewSizePercent=30 -XX:ParallelGCThreads=10 -XX:ConcGCThreads=3 -XX:InitiatingHeapOccupancyPercent=40', I did an echo in MAVEN_OPTS and it return above settings plus global MAVEN_OPTS (at this order). This is not occuring when set JVM Options on freestyle projects. the maven options is always what I set in the job. If you want to mantain this way on pipeline version maybe a option to overwrite global MAVEN_OPTS (true or false) is the best.  
          Hide
          aheritier Arnaud Héritier added a comment -

          yes Andre Crespo I am not sure yet what to do.

          There are several possible combinations and I am not sure what our users are considering as a normal behavior

          • MAVEN_OPTS set and mavenOpts not set => MAVEN_OPTS used (obvious)
          • mavenOpts set and MAVEN_OPTS not set => mavenOpts used (obvious)
          • MAVEN_OPTS and mavenOpts set =>
            • Today MAVEN_OPTS overrides common definitions with mavenOpts because it is appended after it. It's wrong from my POV
            • We could decide to just use mavenOpts when set but do we have users who could find useful to override only some parameters defined globally
            • We could just decide to append mavenOpts after MAVEN_OPTS to override it but I agree with you that it could be surprising (we should probably log it better)
            • I would love to have something flexible but not easy to do with a syntax like withEnv ( https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#withenv-set-environment-variables ) and I am not really fan of having too much parameters (but it's maybe the best option to let everyone choose his behavior)

          Any advice Jesse Glick on how I could do this properly ?

           

          Show
          aheritier Arnaud Héritier added a comment - yes Andre Crespo  I am not sure yet what to do. There are several possible combinations and I am not sure what our users are considering as a normal behavior MAVEN_OPTS set and mavenOpts not set => MAVEN_OPTS used (obvious) mavenOpts set and MAVEN_OPTS not set => mavenOpts used (obvious) MAVEN_OPTS and mavenOpts set => Today MAVEN_OPTS overrides common definitions with mavenOpts because it is appended after it. It's wrong from my POV We could decide to just use mavenOpts when set but do we have users who could find useful to override only some parameters defined globally We could just decide to append mavenOpts after MAVEN_OPTS to override it but I agree with you that it could be surprising (we should probably log it better) I would love to have something flexible but not easy to do with a syntax like withEnv ( https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#withenv-set-environment-variables  ) and I am not really fan of having too much parameters (but it's maybe the best option to let everyone choose his behavior) Any advice Jesse Glick  on how I could do this properly ?  
          Hide
          jglick Jesse Glick added a comment -

          The current behavior seems least surprising. If someone dislikes it, they can use withEnv to suppress MAVEN_OPTS in some block, or just avoid setting it at the node level to begin with.

          Show
          jglick Jesse Glick added a comment - The current behavior seems least surprising. If someone dislikes it, they can use withEnv to suppress MAVEN_OPTS in some block, or just avoid setting it at the node level to begin with.
          Hide
          acrespo Andre Crespo added a comment -

          This is my solution but not my first try because am migrating from freestyle and this is not the behavior on freestyle. I think that the same behavior is needed or some kind of help to explain that the behavior is different.

          Show
          acrespo Andre Crespo added a comment - This is my solution but not my first try because am migrating from freestyle and this is not the behavior on freestyle. I think that the same behavior is needed or some kind of help to explain that the behavior is different.

            People

            Assignee:
            aheritier Arnaud Héritier
            Reporter:
            boby8064 Sadguru Chikkam
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: