I am working on creating CI/CD pipeline for Spring Boot application on GKE using JenkinsX. As soon as I push the code to the master branch, build gets triggered but the build fails due to insufficient Java heap space.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:3.2.2:war (default-war) on project location-finder-api: Error assembling WAR: Problem creating war: Execution exception: Java heap space -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-war-plugin:3.2.2:war (default-war) on project location-finder-api: Error assembling WAR: Problem creating war: Execution exception
Caused by: java.lang.OutOfMemoryError: Java heap space
at org.codehaus.plexus.archiver.zip.ByteArrayOutputStream.needNewBuffer (ByteArrayOutputStream.java:153)
at org.codehaus.plexus.archiver.zip.ByteArrayOutputStream.write (ByteArrayOutputStream.java:192)
To resolve I tried to set the JVM argument in the Docekrfile as
CMD ["java", "-Xmx1024m","-jar", "app.jar"]
But it did not work. This is what I see when the build starts
+ mvn -e clean deploy -Pprod
Picked up _JAVA_OPTIONS: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Dsun.zip.disableMemoryMapping=true -XX:+UseParallelGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Xms10m -Xmx192m
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Is there any way that I can set this heap option on my own?
it looks like maven is running out of memory so you need more memory in your build pod (not the Dockerfile for your app).
as a quick test you can edit the pod template inside the Jenkins UI: jx console
then Manage Jenkins -> Configure System
then find the jenkins-maven
pod template in the UI and edit the _JAVA_OPTIONS
environment variable from this value: https://github.com/jenkins-x/jenkins-x-platform/blob/master/jenkins-x-platform/values.yaml#L907 - try change -Xmx512m
to something bigger like -Xmx912m
Once you've found a value that works for your projects you can make the change permanent of restarts of Jenkins by adding this to your myvalues.yaml
- something like this...
# myvalues.yaml
jenkins:
Agent:
PodTemplates:
Maven:
Name: maven
Label: jenkins-maven
EnvVars:
_JAVA_OPTIONS: '-XX:+UnlockExperimentalVMOptions -Dsun.zip.disableMemoryMapping=true -XX:+UseParallelGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Xms10m -Xmx912m'
see the docs on creating/configuring builders