How to track out of memory errors in Jenkins

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

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 Jenkins Platform or CloudBees Jenkins Team 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 Jenkins is installed to enabled OOME tracking.

Linux

Debian-based distributions (e.g., Debian, Ubuntu)

  1. Add the following option to JAVA_ARGS in /etc/default/jenkins (If JAVA_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;\"
    
  2. Restart Jenkins.

Fedora or openSUSE based distributions (e.g., CentOS, Fedora, openSUSE, Red Hat Enterprise Linux, SUSE Linux)

  1. Add the following option to JENKINS_JAVA_OPTIONS in /etc/sysconfig/jenkins (If JENKINS_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;\"
    
  2. Restart Jenkins.

Windows

Jenkins installed as a Windows service

  1. 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\ &amp;&amp; echo %p > %BASE%\support\oome\%p.pid"
    
  2. Restart Jenkins.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.