0

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?

Swapnil
  • 801
  • 3
  • 19
  • 42

1 Answers1

2

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

James Strachan
  • 9,168
  • 34
  • 31
  • This solution worked for the build. But now the problem is if I hit the URL (using jx open --env staging), it returns 503. Do I need to do any setting for nginx as I know Jenkinsx deploys the app behind nginx server? – Swapnil Apr 17 '19 at 07:08
  • does `jx open` work in the development namespace - e.g. can you view Jenkins / Nexus? The install of Jenkins X should install the ingress controller which is used for all environments + namespaces and all exported services / web apps / REST APIs. If ingress isn't working it could be the domain you used. Are you on premise? see https://jenkins-x.io/getting-started/install-on-cluster/#installing-jenkins-x-on-premise – James Strachan Apr 18 '19 at 07:10
  • Yes, jx open command works. It gives output for jenkins, nexus, jenkins-x-chartmuseum, jenkins-x-docker-registry, jenkins-x-monocular-api, jenkins-x-monocular-ui. How can I check whether the ingress controller is deployed? I am not on premise. Jenkinsx is deployed on Google Kubernetes Engine. – Swapnil Apr 18 '19 at 07:25
  • I reinstalled the jx. In the logs, I could see that nginx is installed. INFO[0463] nginx ingress controller installed and configured. Could you please let me know, how can I fix this issue? – Swapnil Apr 18 '19 at 09:12
  • The project I am working on was already developed in Spring boot. So I am using jx import. I checked all the demos where all of the demo applications are created using jx create. Is there any difference in the environment setup due to jx create. Also, my application does not have a dependency on Spring boot actuator. Is it mandatory to add its dependency in pom.xml? – Swapnil Apr 19 '19 at 00:14
  • Are all of the URLs returned by `jx open` not working? When you ran `jx create cluster gke` did you accept the default values for Ingress & domain? Or did you try use DNS & custom domain? What is the output of `jx open` – James Strachan Apr 19 '19 at 09:24
  • All of the URLs returned by jx open are working. I accepted the default values while installing. – Swapnil Apr 19 '19 at 10:29