[jenkins] How to give Jenkins more heap space when it´s started as a service under Windows?

I want to increase the available heap space for Jenkins. But as it is installed as a service I don´t know how to do it.

This question is related to jenkins heap jvm-arguments

The answer is


In your Jenkins installation directory there is a jenkins.xml, where you can set various options. Add the parameter -Xmx with the size you want to the arguments-tag (or increase the size if its already there).


If you are using Jenkins templates you could have additional VM settings defined in it and this might conflicting with your system VM settings

example your tempalate may have references such as these

 <mavenOpts>-Xms512m -Xmx1024m -Xss1024k -XX:MaxPermSize=1024m -Dmaven.test.failure.ignore=false</mavenOpts> 

Ensure to align these template entries with the VM setting of your system


You need to modify the jenkins.xml file. Specifically you need to change

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

to

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

You can also verify the Java options that Jenkins is using by installing the Jenkins monitor plugin via Manage Jenkins / Manage Plugins and then navigating to Managing Jenkins / Monitoring of Hudson / Jenkins master to use monitoring to determine how much memory is available to Jenkins.

If you are getting an out of memory error when Jenkins calls Maven, it may be necessary to set MAVEN_OPTS via Manage Jenkins / Configure System e.g. if you are running on a version of Java prior to JDK 1.8 (the values are suggestions):

-Xmx2048m  -XX:MaxPermSize=512m

If you are using JDK 1.8:

-Xmx2048m

If you used Aptitude (apt-get) to install Jenkins on Ubuntu 12.04, uncomment the JAVA_ARGS line in the top few lines of /etc/default/jenkins:

# arguments to pass to java
#JAVA_ARGS="-Xmx256m"   # <--default value
JAVA_ARGS="-Xmx2048m"
#JAVA_ARGS="-Djava.net.preferIPv4Stack=true" # make jenkins listen on IPv4 address

I've added to /etc/sysconfig/jenkins (CentOS):

# Options to pass to java when running Jenkins.
#
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Xmx1024m -XX:MaxPermSize=512m"

For ubuntu the same config should be located in /etc/default


From the Jenkins wiki:

The JVM launch parameters of these Windows services are controlled by an XML file jenkins.xml and jenkins-slave.xml respectively. These files can be found in $JENKINS_HOME and in the slave root directory respectively, after you've install them as Windows services.

The file format should be self-explanatory. Tweak the arguments for example to give JVM a bigger memory.

https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service


Examples related to jenkins

Maven dependencies are failing with a 501 error Jenkins pipeline how to change to another folder Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock groovy.lang.MissingPropertyException: No such property: jenkins for class: groovy.lang.Binding How to solve npm install throwing fsevents warning on non-MAC OS? Run bash command on jenkins pipeline Try-catch block in Jenkins pipeline script How to print a Groovy variable in Jenkins? Jenkins pipeline if else not working Error "The input device is not a TTY"

Examples related to heap

Android Gradle Could not reserve enough space for object heap How to increase application heap size in Eclipse? Increase JVM max heap size for Eclipse Command-line Tool to find Java Heap Size and Memory Used (Linux)? how to increase java heap memory permanently? Finding the median of an unsorted array Find running median from a stream of integers Object creation on the stack/heap? How can building a heap be O(n) time complexity? Why should C++ programmers minimize use of 'new'?

Examples related to jvm-arguments

Is JVM ARGS '-Xms1024m -Xmx2048m' still useful in Java 8? What does -Xmn jvm option stands for How to increase IDE memory limit in IntelliJ IDEA on Mac? What does -XX:MaxPermSize do? “Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G What is the largest possible heap size with a 64-bit JVM? How to give Jenkins more heap space when it´s started as a service under Windows? Increasing the JVM maximum heap size for memory intensive applications Java stack overflow error - how to increase the stack size in Eclipse? Difference between -XX:+UseParallelGC and -XX:+UseParNewGC