Featured image of post Recommended Java Settings for Jenkins with Java 11

Recommended Java Settings for Jenkins with Java 11

This is a quick post after fighting with Jenkins and researching a lot of Java documentation.

CloudBees (the company behind the Commercial Support to Jenkins) have a great documentation with recommended Java settings for the JVM being used by Jenkins, but as I found today, those settings are not fully compatible with Java 11, seems to be useful only for Java 8. But fear no more!

After checking different resources (links below) I was able to map the different removed/deprecated settings with “new” Java 11. So I went from this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-XX:+AlwaysPreTouch
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=${PATH}
-XX:+UseG1GC
-XX:+UseStringDeduplication
-XX:+ParallelRefProcEnabled
-XX:+DisableExplicitGC
-XX:+UnlockDiagnosticVMOptions
-XX:+UnlockExperimentalVMOptions
-verbose:gc
-Xloggc:${PATH}/gc.log  *Note that the slash should be adjusted for your operating system, i.e. Windows uses* \
-XX:NumberOfGCLogFiles=2
-XX:+UseGCLogFileRotation
-XX:GCLogFileSize=100m
-XX:+PrintGC
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-XX:+PrintHeapAtGC
-XX:+PrintGCCause
-XX:+PrintTenuringDistribution
-XX:+PrintReferenceGC
-XX:+PrintAdaptiveSizePolicy
-XX:ErrorFile=${PATH}/hs_err_%p.log  *Note that the slash should be adjusted for your operating system, i.e. Windows uses* \
-XX:+LogVMOutput    (requires -XX:+UnlockDiagnosticVMOptions)
-XX:LogFile=${PATH} (requires -XX:+UnlockDiagnosticVMOptions)"
* *Example: `-XX:LogFile=/var/log/jenkins/jvm.log` (Linux)*
* *Example: `-XX:LogFile="C:\Program Files (x86)\Jenkins\jvm.log"` (Windows)*

To this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
-XX:+AlwaysPreTouch
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/var/log/$NAME/
-XX:+UseG1GC
-XX:+UseStringDeduplication
-XX:+ParallelRefProcEnabled
-XX:+DisableExplicitGC
-XX:+UnlockDiagnosticVMOptions
-XX:+UnlockExperimentalVMOptions
-Xlog:gc*,gc+heap=trace,gc+age*=trace,gc+ref*=trace,gc+ergo*=trace:file=/var/log/$NAME/gc-%t.log:utctime:filecount=2,filesize=100m
-XX:ErrorFile=/var/log/$NAME/hs_err_%p.log
-XX:+LogVMOutput
-XX:LogFile=/var/log/$NAME/hs_%p.log

And this is the conversion used:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
-verbose:gc -> Not needed as it is overridden by -Xlog:gc
-Xloggc:${PATH}/gc.log -> -Xlog output file=/var/log/$NAME/gc-%t.log
-XX:NumberOfGCLogFiles=2 -> -Xlog output-options filecount=2
-XX:+UseGCLogFileRotation -> -Xlog:gc+age*=level - Old setting may not be recommended
-XX:GCLogFileSize=100m -> -Xlog output-options filesize=100m
-XX:+PrintGC -> -Xlog:gc
-XX:+PrintGCDateStamps -> Xlog decorator utctime
-XX:+PrintGCDetails -> -Xlog:gc*
-XX:+PrintHeapAtGC -> -Xlog:gc+heap=trace
-XX:+PrintGCCause -> Not needed anymore
-XX:+PrintTenuringDistribution -> -Xlog:gc+age*=level
-XX:+PrintReferenceGC -> -Xlog:gc+ref*=debug
-XX:+PrintAdaptiveSizePolicy -> -Xlog:gc+ergo*=level

Those may not be the unique Java settings to setup in your Jenkins, please check -Xmx and -Xms too.

If you need help in where/how to setup those Java Args in Jenkins please check the Jenkins documentation

I hope this helps somebody who needs to use Jenkins with Java 11!

java-8-11-duke

Resources

Built with Hugo
Theme Stack designed by Jimmy