How do you tune the Jenkins controller JVM and avoid out-of-memory crashes?
AdvancedProductionJenkins in Production
Answer
Set heap explicitly (-Xms equal to -Xmx, typically 4–16 GB, leaving OS headroom), use G1GC, and enable heap dump on OOM. The usual memory hogs: thousands of builds retained, giant build logs, plugins leaking, and too many concurrent Pipeline runs. Limit retention with buildDiscarder, avoid printing megabytes to the console, and use the Metrics/Prometheus plugin to track heap and GC.
JAVA_OPTS="-Xms4g -Xmx4g -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/jenkins_home/dumps -Djenkins.install.runSetupWizard=false"
More on Jenkins in Production
How do you run Jenkins for high availability and scale?AdvancedHow do you back up and restore Jenkins?IntermediateHow do you upgrade Jenkins and its plugins safely?IntermediateHow do you harden a Jenkins controller?AdvancedHow do you configure dynamic Kubernetes agents in Jenkins for production use?IntermediateWhat are the pitfalls of Docker socket mounting in Jenkins agents, and what are alternatives?Advanced