How to add Java arguments to Jenkins?

Issue

  • Don’t know how to add/update Java arguments to CloudBees Jenkins Platform or Managed Master

Environment

  • Jenkins
  • CloudBees Jenkins Enterprise (CJE) Managed Master
  • CloudBees Jenkins Platform (CJP) Client Master
  • CloudBees Jenkins Platform (CJP) Operations Center

Resolution

It depends on the way you ran Jenkins.

Note:

1.- The Jenkins System Properties are added as Java Arguments.
2.- For CJE cluster see How to add Java arguments to CJE Operations Center

Running Jenkins inside Jetty Winstone container

This is the default way to run Jenkins if you installed Jenkins using system packages.

In order to pass Java arguments to Jenkins you need to change the Jenkins service configuration file. It requires root access to the machine.

In CloudBees Jenkins Enterprise, you can find this file under:

  • /etc/default/jenkins: location for most of the Linux distributions.
  • /etc/sysconfig/jenkins: location for RedHat/CentOS distribution.
  • C:\Program Files\Jenkins\jenkins.xml: default location for Windows.

In CloudBees Jenkins Operations Center, you can find this file under:

  • /etc/default/jenkins-oc: location for most of the Linux distributions.
  • /etc/sysconfig/jenkins-oc: location for RedHat/CentOS distribution.
  • C:\Program Files\Jenkins-OC\jenkins.xml: default location for Windows.

Debian / Ubuntu based Linux distributions

If your configuration file is under  /etc/default/ look for the argument JAVA_ARGS. It should look something like this:

JAVA_ARGS="-Djava.awt.headless=true"

Then, add the arguments:

JAVA_ARGS="-Xmx2048m -XX:MaxPermSize=512m -Djava.awt.headless=true"

RedHat Linux based distributions

If your configuration file is under /etc/sysconfig/ look for the argument JENKINS_JAVA_OPTIONS. It should look something like this:

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"

Then, add the arguments:

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

Running Jenkins in Windows as a Service

If configuration file jenkins.xml is located under the Jenkins installation directory - commonly C:\Program Files\Jenkins\ or C:\Program Files\Jenkins-OC\. Then add the arguments into the <arguments> tag. It should look like this::

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

Running Jenkins inside Docker

The JAVA_OPTS should be passed to the container via --env JAVA_OPTS="..." like the following:

docker run --name myjenkins -p 8080:8080 -p 50000:50000 --env JAVA_OPTS="-Xmx2048m -XX:MaxPermSize=512m" jenkins

Note: With Docker, in terms of memory, other constraints apply.

Managed Masters

Go to Managed Master > Configuration > Provisioning > Advanced

  • For Java Heap size ( -Xmx), using a combination of:

  • Jenkins Master Memory in MB: This is the amount of RAM that will be given to the container, expressed in megabytes. The heap given to the Master JVM will be a ratio of this memory.

  • JVM Max heap ratio: The ratio of the memory set under “Jenkins Master Memory in MB” to use as heap for the Jenkins master JVM. This must be a decimal between 0 and 1. Values over 0.7 are not recommended and can cause master restarts when running out of memory.
  • For any others: System Properties

  • Before 1.7.1 - just JAVA_OPTS. For instance:

  JAVA_OPTS=-XX:+PrintGCDetails

* Since 1.7.1 - JAVA_OPTS+[OTHER_VARIABLE]. For instance:

  JAVA_OPTS+MANAGED_MASTER =-XX:+PrintGCDetails

Running Jenkins inside Tomcat

Use environment variable CATALINA_OPTS:

export CATALINA_OPTS="-DJENKINS_HOME=/path/to/jenkins_home/ -Xmx512m"

It is recommended to configure it in the script $CATALINA_BASE/bin/setenv.sh (linux) or %CATALINA_BASE%\bin\setenv.bat (windows) that you’ll create to customize your application server.

Running Jenkins inside another JEE container

Please refer to the documentation of the container you are using.

Running CloudBees Jenkins Platform for Pivotal Cloud Foundry

You need access to the PCF Ops Manager to do it. Open the CloudBees Jenkins Platform tile. On the Settings tab switch to the Jenkins Master pane. Enter arguments into the JVM arguments fields.

Please note that this arguments will apply to all the Jenkins Enterprise and Jenkins Operations Center instances.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.