How can I update managed controller Java Options and Jenkins Options programmatically?

Issue

  • Don’t know how to add/update Java arguments to Jenkins in CloudBees CI Modern programmatically.

Environment

Resolution

You can use different approaches to get these settings updated in your Managed controllers. The options involving the usage of the UI are described in How to add Java arguments to Jenkins on CloudBees CI Modern.

If you want to use a programmatic approach, you can take advantage of the following groovy snippet:

import com.cloudbees.masterprovisioning.kubernetes.KubernetesMasterProvisioning  
import com.cloudbees.opscenter.server.model.ManagedMaster  
def managed_controller="YOUR_MANAGED_CONTROLLER_NAME"  

def instance = jenkins.model.Jenkins.instanceOrNull.getItemByFullName(managed_controller, ManagedMaster.class)  
instance.getConfiguration().setJavaOptions("YOUR_JAVA_OPTIONS")
instance.getConfiguration().setJenkinsOptions("YOUR_JENKINS_OPTIONS")
instance.save()  

These settings will be applied upon the managed controller restart.

You will have different options to run the snippet above:

Note: Java Options may contain System Properties, they are prefixed with -D. System Properties cannot contain Java Arguments such as -XshowSettings:vm or -XX:*.

References

Tested Version

Have more questions?

0 Comments

Please sign in to leave a comment.