Issue
When Jenkins throws an OutOfMemoryError (OOME), the instance is in an undefined state, and must be restarted. How can I configure Jenkins to notify administrators when an OOME occurs so that the instance can be restarted?
Environment
-
CloudBees Support Plugin >= 3.14
Resolution
CloudBees Support Plugin 3.14 and newer can be configured to display an error to Jenkins administrators when an OutOfMemoryError is thrown, immediately informing the administrator that the instance is unstable and must be restarted.
New installations of CloudBees CI that contain CloudBees Support plugin 3.14 or newer have OOME tracking enabled by default. When upgrading from an older version of the CloudBees Support Plugin, follow the instructions in the section below corresponding to the platform on which CloudBees CI is installed to enabled OOME tracking.
Linux
Debian-based distributions (e.g., Debian, Ubuntu)
-
Add the following option to
JAVA_ARGS
in/etc/default/jenkins
(IfJAVA_ARGS
already contains$JENKINS_JAVA_OOME_OPTIONS
then tracking is already enabled and no changes are necessary):-XX:OnOutOfMemoryError=\"\ mkdir -p \\\$JENKINS_HOME/support/oome && \ echo %p > \\\$JENKINS_HOME/support/oome/%p.pid;\"
-
Restart Jenkins.
Fedora or openSUSE based distributions (e.g., CentOS, Fedora, openSUSE, Red Hat Enterprise Linux, SUSE Linux)
-
Add the following option to
JENKINS_JAVA_OPTIONS
in/etc/sysconfig/jenkins
(IfJENKINS_JAVA_OPTIONS
already contains$JENKINS_JAVA_OOME_OPTIONS
then tracking is already enabled and no changes are necessary):-XX:OnOutOfMemoryError=\"\ mkdir -p $JENKINS_HOME/support/oome && \ echo %p > $JENKINS_HOME/support/oome/%p.pid;\"
-
Restart Jenkins.
Windows
Jenkins installed as a Windows service
-
Add the following option directly before the
-jar
argument in the<arguments>
tag in$JENKINS_HOME/jenkins.xml
, unless it is already present.-XX:OnOutOfMemoryError="cmd.exe /c md %BASE%\support\oome\ && echo %p > %BASE%\support\oome\%p.pid"
-
Restart Jenkins.