Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins configuration as code: programmatically reload configuration from file

Tags:

How to reload Jenkins configuration as code file from within groovy script? (Equivalent of clicking on "Reload existing configuration")

like image 234
Mateusz Jamiołkowski Avatar asked Feb 19 '19 16:02

Mateusz Jamiołkowski


People also ask

What is reload configuration from disk in Jenkins?

Reload Configuration from Disk simply refreshes Jenkins configuration files and directory structure. This command should be used when a change is made to Jenkins and its environment outside of the UI, such as editing config. xml files from the command line or moving jobs between folders from the command line.

What is Jenkins configuration as code?

The Jenkins Configuration as Code (JCasC) feature defines Jenkins configuration parameters in a human-readable YAML file that can be stored as source code. This essentially captures the configuration parameters and values that are used when configuring Jenkins from the web UI.

How do I save Jenkins configuration?

All your jobs is stored in config. xml files inside $JENKINS_HOME/jobs/<path_to_your_job> folders. So, you can just backup these config. xml files (or you can backup all Jenkins configuration by saving full $JENKINS_HOME folder).


1 Answers

Sample groovy script to reload configuration yaml file:

import io.jenkins.plugins.casc.ConfigurationAsCode;
ConfigurationAsCode.get().configure()
like image 156
Mateusz Jamiołkowski Avatar answered Oct 19 '22 23:10

Mateusz Jamiołkowski