Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

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

Automating Jenkins Job Configuration: Job DSL, Multibranch, Job Generator, and JJB

Manually creating many Jenkins jobs is slow and error-prone. This guide compares the main automation options and shows practical jobs-as-code examples for repeatable setup.

Read More

Install Jenkins with Docker: Persistent Setup, Port Mapping, and Logs

Learn how to run Jenkins in Docker with correct port mapping, persistent storage, and operational commands. This updated guide keeps the original workflow but adds modern, production-minded practices.

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

Jenkins Backup and Restore Runbook: ThinBackup, Filesystem Archives, and Recovery Steps

A practical Jenkins backup and restore guide for DevOps teams, covering what to back up, strategy trade-offs, and step-by-step command examples. Includes a workflow diagram and a recovery checklist you can operationalize.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x