How to add Java arguments to Jenkins

Issue

  • Don’t know how to add Java arguments to CloudBees Jenkins Enterprise or CloudBees Jenkins Operations Center

Environment

  • Jenkins
  • CloudBees Jenkins Enterprise (CJE)
  • CloudBees Operations Center (CJOC)

Resolution

It depends on the way you ran Jenkins.

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.

Running Jenkins inside Tomcat

Use environment variable CATALINA_OPTS:

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

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.