Reload Jenkins job configuration from command line without restart

     Hi, Today in this article I will explain Jenkins config reload by command line without interrupting running jobs.

    Jenkins caches configurations while it starts to first run. If you change config files during Jenkins run, no change will be applied because still it will be reading from cache. So we need to reload configration for usage. If we restart Jenkins Server it can reload but it is not a good way to do. You can also reload by Jenkins GUI but for a pipeline it is not good idea using GUI. It is better to handle it by command line interface.

     I have an end-to-end pipeline with Jenkins and lastly I needed to reload a Jenkins job configuration by command line. After a research, I found out how to do that and I wanted to share my experience in here.

Note: ( This article will be explained in Linux but the same steps goes also for Windows machines. For Windows, default Jenkins path is C:\Users\{YOURUSERNAME}\.jenkins folder.

Let’s take a look;

1.) I have an empty Jenkins server from scratch like below. This Jenkins Server is running on a Linux machine.

2.) In Linux default Jenkins path is /var/lib/.jenkins

We can see that there is no job currently as well like Jenkins Web GUI.

3.) Go to Jenkins on browser and click New Item and create a test-job like below.

4.) After create the job,  choose “This project is parameterized” option and fill Name, Default Value and Description sections and after that click Save.

5.) You will see that in Jenkins main page there is a test-job. Click below button to open parameters page of the job.

6.) You will see page like below.

7.)  After creating job we can go to Linux machine to check  /var/lib/jenkins/jobs. You will see that a test-job folder is created. Into test-job folder you will see a config.xml. This file holds job configuration for Jenkins. We can cat to check config.xml file.

8.)  Let’s change config.xml file with vi text editor on Linux.

Add “This file is changed by Linux by config.xml.”   Save and exit (:wq)

9.) Go to Jenkins on browser and refresh test-job parameters page. You will see that no change will happen. The reason of that, Jenkins read configuration during server starts and caches it. So the change is not applied. We need to reload configuration. Let’s do it without restart, without using Jenkins GUI. We can do it by Jenkins Command Line Interface (jenkins-cli.jar)

10.) Add /jnlpJars/jenkins-cli.jar suffix to the link and press Enter. Save jenkins-cli.jar file in a path.

 

11.) Go the path of jenkins-cli.jar file and Open a Terminal. Run command like below;

 

sudo java -jar jenkins-cli.jar -s http://{JenkinsIP}:{JenkinsPort}/ reload-configuration

12.) Reload Jenkins GUI page to see if there is a change;

13.) Yes !!! It reloaded without interrupt a process. 

Note : If you have error like “ERROR: anonymous is missing the Overall/Read permission”

Then go to Jenkins Main Page -> Manage Jenkins -> Configure Global Security settings to check your security policies.

Take care 🙂