Jenkins
Start Jenkins
Startup script to set the System Properties
Step 1:
- Locate the Jenkins home directory. You can look into the existing system properties for ‘jenkins_home’ or execute ‘echo $JENKINS_HOME’ inside the jenkins server to get the Jenkins home directory.
- Say if your Jenkins home directory is ‘/var/jenkins_home’. Create a new directory with name ‘init.groovy.d’.
Step 2:
- Now change your working directory to ‘/var/jenkins_home/init.groovy.d’
- Within init.groovy.d directory create a new groovy script. Say ‘startup-properties.groovy’
Step 3:
- Copy the below content to the ‘startup-properties.groovy’ file
import jenkins.model.Jenkins
import java.util.logging.LogManager
/* Jenkins home directory */
def jenkinsHome = Jenkins.instance.getRootDir().absolutePath
def logger = LogManager.getLogManager().getLogger("")
/* Replace the Key and value with the values you want to set.*/
/* System.setProperty(key, value)*/
System.setProperty("hudson.model.WorkspaceCleanupThread.disabled", "true")
logger.info("Jenkins Startup Script: Successfully updated the system properties. Script location: ${jenkinsHome}/init.groovy.d")
Visit https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/System.html?is-external=true#setProperty(java.lang.String,java.lang.String) to see how to use setProperty.
Step 4:
Restart the Jenkins server, you can manually restart the server using :
<Jenkins-server-URL>/restart or <Jenkins-server-URL>/safeRestart
- Use safeRestart when you have some job still running. It will wait till all the jobs are completed.
Step 5:
Check the logs after Jenkins restart: Manage Jenkins → System Log. You can see while server is starting, its executing the startup-properties.groovy script which is inside init.groovy.d directory.

For example, run the below scripts in Script Console to check the System Properties, you will see the required key and values.
println(System.getProperty("hudson.model.WorkspaceCleanupThread.disabled"))
Now every time server is restarted the script will run and set the system properties for you. You don’t need to worry for setting these system properties manually every time server restart.
https://wiki.jenkins-ci.org/display/JENKINS/Features-controlled-by-system-properties.html
Start docker container with system properties
docker run --name my-jenkins -p 8080:8080 -p 50000:50000 -v /your/jenkins_home:/var/jenkins_home \
-d \
-v /var/run/docker.sock:/var/run/docker.sock \
--env JAVA_OPTS="-Dhudson.model.WorkspaceCleanupThread.disabled=\"true\"" \
--restart unless-stopped \
--user root \
bndynet/jenkins
Plugin: Configuration as Code (aka.JCasC )
Apply configuration from Git
https://<USERNAME>:<PERSON_ACCESS_TOKEN>@github.com/your-repo/jenkins-config.git
Add Nodes
Step 1. In node server, install java by https://sdkman.io/
curl -s "https://get.sdkman.io" | bash
sdk install java 17.0.14-tem
Step 2. Add java path for all users (/etc/environment)
JAVA_HOME=/home/<user>/.sdkman/candidates/java/current
PATH="/home/<user>/.sdkman/candidates/java/current/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
Step 3. Generate ssh key in jenkins server, if you are running jenkins on container, you should enter the container to do that.
ssh-keygen -t rsa -b 4096 -f /var/jenkins_home/id_rsa
Step 4. Copy pub key to node server
ssh-copy-id -i /var/jenkins_home/.ssh/id_rsa.pub username@hostname
Step 5. Add Credentials in jenkins UI with the private key
Step 6. Add Node in jenkins UI with Launch agens via SSH, and choose above Credentials
Q: Could not copy remoting.jar into '/home/jenkins' on agent
If below error thrown:
Permission denied (SSH_FX_PERMISSION_DENIED: The user does not have sufficient permissions to perform the operation.)