Jenkins

How to Set System Properties in Jenkins

Jenkins system properties refer to a set of global variables that can be used in various parts of the system. These system properties can be used to unlock a set of “hidden” features in Jenkins, allowing you to get access to a few experimental features.

In this tutorial, we will learn how to use and access various Jenkins System properties either via the Jenkins user interface or a specific argument on the command line.

Note that system properties are different from environment variables specific to a particular operating system and can be set and accessed differently.

Using Jenkins System Properties

To use Jenkins System Properties, we use the -D argument in the Jenkins command line when starting Jenkins.

The syntax for enabling Jenkins system properties is as shown:

-Dproperty=value

 
Ensure to include all the arguments before the -jar argument; otherwise, the Jenkins-CLI will ignore them.

An example command is as shown:

$ java -Dhudson.footerURL=http://localhost:8080 -jar jenkins.war

 
Another method we can use to access and set system properties in Jenkins is using the Jenkins Script console.

Example 1

The following example shows how to use the Jenkins script console to set the value for the Client-side HTTP CLI ping interval in milliseconds.

System.setProperty("hudson.cli.CLI.pingInterval", "3000");

 
The command above should set the default ping interval to 3000 milliseconds.

It is good to note that the Jenkins server will reset the system properties to default when the server reboots. You can permanently set the system properties values by creating a Jenkins startup script.

This will force Jenkins to load the startup script upon launch.

To create a startup script in Jenkins:

Locate the Jenkins home directory by running the command:

$ echo $JENKINS_HOME

 
For example, if your Jenkins home is set to /var/lib/jenkins. You can add a file called init.groovy.d

To discover the various system properties, you can enable or configure in your Jenkins server, check the resource below:

https://www.jenkins.io/doc/book/managing/system-properties/

Conclusion

Jenkins system properties are global variables that can be used to configure various aspects of the Jenkins system.

We can configure the Jenkins system properties using the -D flag in the Jenkins CLI or the script console on the Jenkins Dashboard.

System properties help control Jenkins’ behavior and create custom configurations for jobs and projects. It is good to note that enabling or changing the configuration of various system properties can come with high costs, such as security and resource. Consider the impact of each property before making any modifications.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list