Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to keep Hudson / Jenkins configuration files in source control?

People also ask

How do I save Jenkins configuration?

Use the UI of the current system to install and configure the plugin. Click Apply >> Save to save the configuration. Use Manage Jenkins >> Configuration as Code >> View Configuration to view the JCasC file with the plugin configured. Click on Download Configuration to save the modified configuration file locally.

Where does Jenkins keep the configuration data?

The job configuration file is {JENKINS_HOME}/jobs/{JOBNAME}/config. xml. The job builds are stored in {JENKINS_HOME}/jobs/{JOBNAME}/builds/

Where does Jenkins store job configs?

Jenkins stores the configuration for each job within an eponymous directory in jobs/. The job configuration file is config. xml, the builds are stored in builds/, and the working directory is workspace/.

What is the use of config xml in Jenkins?

The config. xml file contains information about Jenkins like version, Pipeline information, owner, etc. It also contains the workspace Directory path, builds Directory path.


Most helpful Answer

There is a plugin called SCM Sync configuration plugin.


Original Answer

Have a look at my answer to a similar question. The basic idea is to use the filesystem-scm-plugin to detect changes to the xml-files. Your second part would be committing the changes to SVN.

EDIT: If you find a way to determine the user for a change, let us know.

EDIT 2011-01-10 Meanwhile there is a new plugin: SCM Sync configuration plugin. Currently it only works with subversion and git, but support for more repositories is planned. I am using it since version 0.0.3 and it worked good so far.


Note that Vogella has a recent (January 2014, compared to the OP's question January 2010) and different take on this.
Consider that the SCM Sync configuration plugin can generate a lot of commits.
So, instead of relying on a plugin and an automated process, he manages the same feature manually:

Storing the Job information of Jenkins in Git

I found the amount of commits a bit overwhelming, so I decided to control the commits manually and to save only the Job information and not the Jenkins configuration.
For this switch into your Jenkins jobs directory (Ubuntu: /var/lib/jenkins/jobs) and perform the “git init” command.

I created the following .gitignore file to store only the Git jobs information:

builds/
workspace/
lastStable
lastSuccessful
nextBuildNumber
modules/
*.log

Now you can add and commit changes at your own will.
And if you add another remote to your Git repository you can push your configuration to another server.

Alberto actually recommend to add as well (in $JENKINS_HOME):

  • jenkins own config (config.xml),
  • the jenkins plugins configs (hudson*.xml) and
  • the users configs (users/*/config.xml)

To manually manage your configuration with Git, the following .gitignore file may be helpful.

# Miscellaneous Hudson litter
*.log
*.tmp
*.old
*.bak
*.jar
*.json

# Generated Hudson state
/.owner
/secret.key
/queue.xml
/fingerprints/
/shelvedProjects/
/updates/

# Tools that Hudson manages
/tools/

# Extracted plugins
/plugins/*/

# Job state
builds/
workspace/
lastStable
lastSuccessful
nextBuildNumber

See this GitHub Gist and this blog post for more details.


There is a new SCM Sync Configuration plug-in which does exactly what you are looking for.

SCM Sync Configuration Hudson plugin is aimed at 2 main features :

  • Keep sync'ed your config.xml (and other ressources) hudson files with a SCM repository
  • Track changes (and author) made on every file with commit messages

I haven't actually tried this yet, but it looks promising.


You can find configuration files in Jenkins home folder (e.g. /var/lib/jenkins).

To keep them in VCS, first login as Jenkins (sudo su - jenkins) and create its git credentials:

git config --global user.name "Jenkins"
git config --global user.email "[email protected]"

Then initialize, add and commit the basic files such as:

git init
git add config.xml jobs/ .gitconfig
git commit -m'Adds Jenkins config files' -a

also consider creating .gitignore with the following files to ignore (customize as needed):

# Git untracked files to ignore.

# Cache.
.cache/

# Fingerprint records.
fingerprints/

# Working directories.
workspace/

# Secret files.
secrets/
secret.*
*.enc
*.key
users/
id_rsa

# Plugins.
plugins/

# State files.
*.state

# Job state files.
builds/
lastStable
lastSuccessful
nextBuildNumber

# Updates.
updates/

# Hidden files.
.*
# Except git config files.
!.git*
!.ssh/

# User content.
userContent/

# Log files.
logs/
*.log

# Miscellaneous litter
*.tmp
*.old
*.bak
*.jar
*.json
*.lastExecVersion

Then add it: git add .gitignore.

When done, you can add job config files, e.g.

shopt -s globstar
git add **/config.xml
git commit -m'Added job config files' -a

Finally add and commit any other files if needed, then push it to the remote repository where you want to keep the config files.


When Jenkins files are updated, you need to reload them (Reload Configuration from Disk) or run reload-configuration from Jenkins CLI.