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

Resolution

It depends on the way you ran Jenkins.

Note: The Jenkins System and Remoting Properties are added as Java Arguments.

Testing the properties

IMPORTANT: This type of setting is not persistent thus the property default values will be reset after the next restart.

In the Script Console, depending on the property setting.

Most of the Jenkins properties are static, therefore you can update its value like in the following examples:

TcpSlaveAgentListener.CLI_HOST_NAME="<cje.example>"
//OR
com.cloudbees.hudson.plugins.folder.computed.FolderComputation.BACKUP_LOG_COUNT=10

There are some exceptions like the JENKINS-35484 which makes use of the Jenkins SystemProperties

Traditional Platform

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"

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.

Cloud Platform

CJE 1.x

Operation Center

How to add Java arguments to CJE Operations Center

Managed Masters

Go to CJOC Dashboard and click on Configure on the Managed Master you want to add the Java argument.

mmconfiguration

Once here, you can add your Java arguments under Provisioning>Java Options (separated with blank spaces, not line breaks).

  • 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 according to the instance capabilities. For instance in AWS, see instance types.
    • 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 (older Jenkins versions)
    • 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.

CJE 2.x

Managed Masters

Go to CJOC Dashboard and click on Configure on the Managed Master you want to add the Java argument.

mmconfiguration

Once here, you can add your Java arguments under Provisioning>Java Options (separated with blank spaces, not line breaks).

Operation Center

List all your statefulset

$> kubectl get statefulsets
NAME      DESIRED   CURRENT   AGE
cjoc      1         1         11d
...

Edit cjoc statefulsets by

$> kubectl edit statefulsets cjoc

Then edit

...
    spec:
      containers:
      - env:
          ...  
        - name: JAVA_OPTS
          value: -XshowSettings:vm -XX:MaxRAM=${MEM_LIMIT}m -XX:MaxRAMFraction=1 -XX:+PrintGCDetails
            -Dcb.IMProp.warProfiles=kubernetes.json -Dcb.IMProp.warProfiles.cje=kubernetes.json
            -Dcom.cloudbees.opscenter.analytics.reporter.JocAnalyticsReporter.PERIOD=120
            -Dcom.cloudbees.opscenter.analytics.reporter.metrics.AperiodicMetricSubmitter.PERIOD=120
            -Dcom.cloudbees.opscenter.analytics.FeederConfiguration.PERIOD=120 -Dcom.cloudbees.masterprovisioning.kubernetes.KubernetesMasterProvisioning.fsGroup=1000
            -Dhudson.lifecycle=hudson.lifecycle.ExitLifecycle -Dcom.cloudbees.jce.masterprovisioning.DockerImageDefinitionConfiguration.disableAutoConfiguration=true
            -Dcom.cloudbees.jce.masterprovisioning.DockerImageDefinitionConfiguration.masterImageName="CloudBees
            Core - Managed Master 2.138.1.2" -Dcom.cloudbees.jce.masterprovisioning.DockerImageDefinitionConfiguration.masterImage=cloudbees/cloudbees-core-mm:2.138.1.2
Have more questions? Submit a request

4 Comments

  • 0
    Avatar
    Avi Kessner

    How can I update the statefulset yaml file, instead of editing the sts directly on the cluster?

  • 0
    Avatar
    Fabian Röber

    @avi kessner

    with kubectl apply -f <yourfile.yaml>

    this does only work if files have been initially pushed with apply -f (and not create -f)

  • 0
    Avatar
    Avi Kessner

    When using apply, it gives a warning that the statefulset is not updated.  Do we need to remove the statefulset first?

  • 0
    Avatar
    Denys Digtiar

    Hi Avi,

    Have you first updated the sts/cjoc in the cloudbees-core.yml before applying it?

    Feel free to create a support ticket if this does not help you.

Please sign in to leave a comment.