Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

How to Resolve jenkins java.lang.outofmemoryerror permgen space issues?

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

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

Solution 1

In Windows: Go to environment variable and add following variables

export JAVA_OPTS=”-XX:MaxPermSize=512m -Xms512m -Xmx1024m”
export GRADLE_OPTS=”-XX:MaxPermSize=512m”
export SONAR_RUNNER_OPTS=”-Xmx512m -XX:MaxPermSize=512m”

In Linux:
In my ~/.bash_profile file, I have set the following 3 variables. Note there are other variables in this file as well i.e. JAVA_HOME, ANT_HOME, SONAR_HOME, SONAR_RUNNER_HOME, etc:

export JAVA_OPTS=”-XX:MaxPermSize=512m -Xms512m -Xmx1024m”
export GRADLE_OPTS=”-XX:MaxPermSize=512m”
export SONAR_RUNNER_OPTS=”-Xmx512m -XX:MaxPermSize=512m”

Solution 2
You can set the -Xmx or -XX:MaxPermSize in your Jenkins global configuration. To do this, navigate to Jenkins global configuration page (Manage Jenkins -> Configure System)

Name – JAVA_OPTS
Value – “-XX:MaxPermSize=512m -Xms512m -Xmx1024m”

You can set similarlity for maven, gradle, sonar as well under “Maven Project Configuration” or grade project configuration.

Name – GRADLE_OPTS
Value – “-XX:MaxPermSize=512m”

Solution 3

They way you can modify this value depends on the distribution and depending on the slave type

Master

In RedHat, for example, you can do it under /etc/sysconfig/jenkins using the variable JENKINS_JAVA_OPTIONS… i.e JENKINS_JAVA_OPTIONS=”-XX:MaxPermSize=512m”.
In Ubuntu, the Jenkins configuration file is under /etc/default/jenkins and the variable to configure is JAVA_ARGS … i.e JAVA_ARGS=”-XX:MaxPermSize=512m”.

Slave

Sometimes slave machines will require permgen to be increased. Depending on the type of slave that is configured will require a different method for setting any java argument.

With SSH Slaves, the java process is started using an SSH command, so the “-XX:MaxPermSize=512m” can be set in the JVM Options in the Node configuration page.
With JNLP Slaves launching as a service on linux, you can add the VM arguments to the startup scripts (usually in /etc/sysconfig/jenkins or /etc/default/jenkins as part of the JAVA_ARGS variable)
With JNLP Slaves launching as a service on Windows requires modifications to be made on the jenkins.xml file which is located on slave machine in the JENKINS_HOME directory.

Reference
http://stackoverflow.com/questions/18000841/jenkins-java-lang-outofmemoryerror-permgen-space
https://wiki.jenkins-ci.org/display/JENKINS/Builds+failing+with+OutOfMemoryErrors
https://cloudbees.zendesk.com/hc/en-us/articles/204264000-Why-do-I-receive-java-lang-OutOfMemoryError-PermGen-space
http://stackoverflow.com/questions/14762162/how-do-i-give-jenkins-more-heap-space-when-its-running-as-a-daemon-on-ubuntu
http://stackoverflow.com/questions/18000841/jenkins-java-lang-outofmemoryerror-permgen-space
http://javarevisited.blogspot.nl/2011/09/javalangoutofmemoryerror-permgen-space.html
https://plumbr.eu/outofmemoryerror/permgen-space

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x