Comprehensive Guide to Increasing Heap Space for Jenkins Service

Nov 23, 2025 · Programming · 7 views · 7.8

Keywords: Jenkins | Heap Memory | Service Configuration

Abstract: This technical article provides a detailed guide on increasing heap memory for Jenkins when running as a service. It covers configuration methods across different operating systems, including specific file locations and parameter settings. The article also discusses memory monitoring and optimization strategies for Maven builds, offering practical solutions for memory-related issues.

Heap Memory Configuration for Jenkins Service

When Jenkins runs as a service, memory configuration requires modification of specific configuration files. Different operating systems and installation methods correspond to different file locations and setup procedures.

Windows System Configuration

In Windows systems, the primary configuration file for Jenkins service is jenkins.xml, typically located in the Jenkins installation directory.

To increase heap memory, add or modify the -Xmx parameter within the <arguments> tag. For example, increasing from the default 256MB to 2048MB:

<arguments>-Xrs -Xmx2048m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%"\jenkins.war" --httpPort=8080</arguments>

Here, -Xmx2048m sets the maximum heap size to 2048MB. The -Xrs parameter reduces Java VM's use of OS signals, improving service stability.

Linux System Variations

On Debian-based systems like Ubuntu, the configuration file is typically at /etc/default/jenkins. Modify the JAVA_ARGS environment variable:

# arguments to pass to java
JAVA_ARGS="-Xmx2048m"

For Red Hat-based systems like CentOS, the configuration path is /etc/sysconfig/jenkins, using the JENKINS_JAVA_OPTIONS variable:

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Xmx1024m -XX:MaxPermSize=512m"

Permanent Generation Configuration Considerations

For versions prior to Java 8, permanent generation (PermGen) memory configuration is also required. Use the -XX:MaxPermSize parameter:

-Xmx2048m -XX:MaxPermSize=512m

Starting from Java 8, PermGen was replaced by Metaspace, eliminating the need for separate -XX:MaxPermSize configuration.

Memory Usage Monitoring and Verification

After configuration, verify memory settings using Jenkins monitoring plugins. Install the Monitoring plugin and check actual memory usage at Manage JenkinsMonitoring of HudsonJenkins master.

Maven Build Configuration

If Jenkins encounters memory issues during Maven builds, configure the MAVEN_OPTS environment variable in system settings. Add the following at Manage JenkinsConfigure System:

-Xmx2048m -XX:MaxPermSize=512m

For Java 8 and later versions:

-Xmx2048m

Configuration Activation and Restart

After modifying configuration files, restart the Jenkins service to apply changes. In Windows, use the service manager; in Linux, use appropriate service management commands:

sudo systemctl restart jenkins  # systemd systems
sudo service jenkins restart    # init systems

After restart, verify the new memory configuration through Jenkins system information pages or monitoring plugins.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.