我正在使用JenkinsX为GKE上的Spring Boot应用程序创建CI / CD管道。一旦将代码推送到master分支,就会触发构建,但是由于Java堆空间不足,构建会失败。
[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)
为解决此问题,我尝试将Docekrfile中的JVM参数设置为
CMD ["java", "-Xmx1024m","-jar", "app.jar"]
但是没有用。这是我开始构建时看到的内容
+ 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
我可以通过任何方式自行设置此堆选项吗?
答案 0 :(得分:1)
看起来maven内存不足,因此您的构建容器中需要更多的内存(而不是应用程序的Dockerfile)。
作为快速测试,您可以在Jenkins UI中编辑pod模板:jx console
然后Manage Jenkins -> Configure System
然后在UI中找到jenkins-maven
pod模板并编辑_JAVA_OPTIONS
环境变量的值从以下值开始:https://github.com/jenkins-x/jenkins-x-platform/blob/master/jenkins-x-platform/values.yaml#L907-尝试将-Xmx512m
更改为类似-Xmx912m
一旦找到了适合您项目的值,就可以通过将其添加到myvalues.yaml
中来使更改永久生效,例如将Jenkins重新添加到您的项目中……
# 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'