MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Fix Jenkins java.lang.OutOfMemoryError: PermGen Space (Controller, Agents, and Build Tools)

Originally published on 2015-09-03; fully revised and updated.

If Jenkins jobs fail with java.lang.OutOfMemoryError: PermGen space, the practical fix is to apply JVM memory flags in the correct scope: Jenkins controller, Jenkins agent, or the build tool process itself. This walkthrough explains where to set those options on Linux and Windows, how to validate them, and what to do on modern Java versions where PermGen no longer exists.

jenkins-java-lang-outofmemoryerror-permgen-space-issues

What this Jenkins error usually means

The original error references PermGen, which applies to older JVMs (typically Java 7 and earlier). In Jenkins environments, failures may come from different JVMs, not only the Jenkins controller process.

  • Controller JVM: Jenkins service itself runs out of memory.
  • Agent JVM: build node (SSH/JNLP/service) launches with low memory flags.
  • Build tool JVM: Maven/Gradle/Sonar runner process is constrained.

For Java 8 and newer, use Metaspace-related flags instead of PermGen flags.

Triage workflow before changing memory settings

flowchart TD
    A[Build fails with OutOfMemoryError] --> B{Failure location}
    B --> C[Controller logs]
    B --> D[Agent logs]
    B --> E[Build tool output]
    C --> F[Check Java major version]
    D --> F
    E --> F
    F --> G{Java 7 or earlier}
    G -- yes --> H[Use Xmx and MaxPermSize]
    G -- no --> I[Use Xmx and MaxMetaspaceSize]
    H --> J[Apply at controller or agent or tool scope]
    I --> J
    J --> K[Restart affected process]
    K --> L[Re-run build and monitor]

Where to set JVM options in Jenkins environments

Configuration pointScopeWhen to useTypical variable/field
OS/service configuration for Jenkins controllerJenkins master/controller JVMController itself crashes or is unstableJAVA_ARGS or JENKINS_JAVA_OPTIONS
Jenkins Global PropertiesEnvironment for jobsBuild steps need memory flagsJAVA_OPTS, GRADLE_OPTS, SONAR_RUNNER_OPTS
Node (agent) JVM optionsSingle agent processOnly specific agents fail with OOMNode JVM options / agent startup arguments
Build tool-specific configurationMaven/Gradle/Sonar processTool process fails while Jenkins remains healthyGRADLE_OPTS, MAVEN_OPTS, SONAR_RUNNER_OPTS

Configuration examples

Set environment variables in Linux shell profiles

The original post used ~/.bash_profile. Keep in mind this affects only processes that inherit that shell environment.

# Java 7 and earlier (PermGen)
export JAVA_OPTS="-XX:MaxPermSize=512m -Xms512m -Xmx1024m"
export GRADLE_OPTS="-XX:MaxPermSize=512m"
export SONAR_RUNNER_OPTS="-Xmx512m -XX:MaxPermSize=512m"

# Java 8+ (Metaspace)
export JAVA_OPTS="-Xms512m -Xmx1024m -XX:MaxMetaspaceSize=512m"
export GRADLE_OPTS="-Xmx1024m -XX:MaxMetaspaceSize=512m"
export SONAR_RUNNER_OPTS="-Xmx512m -XX:MaxMetaspaceSize=512m"Code language: PHP (php)

Set controller JVM flags in Jenkins service config

From the original guidance: RedHat-based installs often use /etc/sysconfig/jenkins and Debian/Ubuntu installs often use /etc/default/jenkins.

# /etc/sysconfig/jenkins (example)
JENKINS_JAVA_OPTIONS="-XX:MaxPermSize=512m -Xms512m -Xmx1024m"

# /etc/default/jenkins (example)
JAVA_ARGS="-XX:MaxPermSize=512m -Xms512m -Xmx1024m"Code language: PHP (php)

If your Jenkins runtime is Java 8 or newer, replace -XX:MaxPermSize with a Metaspace limit such as -XX:MaxMetaspaceSize.

Set job environment in Jenkins global configuration

  • Go to Manage Jenkins → Configure System.
  • Under global environment settings, add name/value pairs such as JAVA_OPTS or GRADLE_OPTS.
  • Use this for job-level runtime tools when service-level tuning is not enough.
Name: JAVA_OPTS
Value: -XX:MaxPermSize=512m -Xms512m -Xmx1024m

Name: GRADLE_OPTS
Value: -XX:MaxPermSize=512mCode language: HTTP (http)

Agent-specific JVM options (SSH/JNLP/Windows service)

Agent configuration depends on launch mode. For Windows JNLP service agents, JVM arguments are commonly set in the agent-side jenkins.xml.

<service>
  <id>jenkins-agent</id>
  <name>Jenkins Agent</name>
  <arguments>-jnlpUrl http://jenkins.example/computer/agent/slave-agent.jnlp -secret ******** -workDir C:\\Jenkins</arguments>
  <executable>java</executable>
  <logmode>rotate</logmode>
  <onfailure action="restart"/>
  <!-- Add JVM flags in the executable arguments per your service wrapper format -->
</service>Code language: HTML, XML (xml)

Verify the applied settings

After changing options, restart the affected process (controller or agent), then confirm runtime flags from the host.

# Confirm Jenkins Java process arguments
ps -ef | grep -i jenkins

# If jcmd is available, inspect effective JVM flags
jcmd $(pgrep -f jenkins | head -n 1) VM.flags

# Confirm environment options in current shell/job context
echo "$JAVA_OPTS"
echo "$GRADLE_OPTS"Code language: PHP (php)

References from the original post

Best practices

  • Identify which JVM is failing before increasing memory globally.
  • Use version-appropriate flags: PermGen for older JVMs, Metaspace for Java 8+.
  • Prefer the narrowest scope first (specific agent/tool) before changing controller-wide defaults.
  • After each change, restart the affected process and verify effective flags from process output.
  • Track memory changes in configuration management so rollback is easy and consistent across nodes.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

jstack Utility Deep Dive: JVM Thread Dumps, Deadlocks, and Mixed Stacks

This guide explains how to use jstack to diagnose JVM hangs and deadlocks, including forced dumps, core-file analysis, and mixed Java/native stack traces. It also clarifies where jcmd fits in modern JDK 8+ troubleshooting guidance.

Read More

Jenkins at Scale: Practical References and Admin Cheatsheet

This revised guide upgrades a short 2015 Jenkins link post into an operations-ready reference for teams running Jenkins at scale. It preserves the original links and adds a workflow diagram, comparison table, and practical API/CLI examples.

Read More

Gerrit Performance Tuning Cheat Sheet: Workflow, Bottlenecks, and Practical Commands

A practical Gerrit performance guide for DevOps and platform engineers. Learn a repeatable tuning workflow, where bottlenecks usually appear, and which commands to run first.

Read More

Jenkins Troubleshooting Guide: Fast Triage, Log Analysis, and Common Failure Fixes

A practical Jenkins troubleshooting guide for DevOps teams: find the right logs first, separate controller vs. agent vs. job failures, and resolve common outage patterns quickly.

Read More

EMMA for Java Code Coverage: Setup, Instrumentation Modes, and J2EE Workflow

EMMA is a Java code coverage tool used to see which code paths are actually exercised by tests and runtime usage. This updated guide explains installation choices, instrumentation modes, and the offline J2EE workflow described in the original post.

Read More

ANT_OPTS in Apache Ant: JVM Memory, Proxy Settings, and Startup Troubleshooting

ANT_OPTS passes JVM options to the Java process that runs Ant. This guide explains how ANT_OPTS differs from ANT_ARGS and JAVACMD, with practical examples for memory tuning, proxy setup, and startup error diagnosis.

Read More
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
1 month ago

PermGen errors in older Jenkins setups can be tricky because the cause may be more than low memory. Checking plugin usage, Java compatibility, and recent configuration changes can help narrow down the issue. Increasing memory may help temporarily, but it should not replace finding the real cause. It is also important to note that newer Java versions use Metaspace instead of PermGen. Matching troubleshooting steps to the installed Java version can save time and prevent repeated failures.

Rahul Yadav
Rahul Yadav
1 month ago

When troubleshooting Jenkins memory errors, it is important to distinguish between a JVM configuration problem and a deeper issue such as a leaking plugin or excessive job concurrency. PermGen-related errors are associated with older Java versions; modern JVMs use Metaspace instead, so the correct fix depends on the Java version running Jenkins. I would inspect heap and garbage-collection metrics, review plugin usage, and check whether memory consumption increases over time before changing JVM settings. Simply increasing memory may postpone the failure without addressing its actual cause.

2
0
Would love your thoughts, please comment.x
()
x