Skip to content

Latest commit

 

History

History
48 lines (30 loc) · 1.67 KB

README.md

File metadata and controls

48 lines (30 loc) · 1.67 KB

Backup jenkins configuration to a git repository

TL;DR: This repository has useful scripts for backing up your jenkins configuration to a git repository.

Inspired by this link, which shows how to keep the jenkins configuration and data in subversion. Well, we're in 2013, so I thought that keeping the configuration in git would be more useful :)

Usage

One-time configuration

  1. Clone the repo:
git clone git@github.com:luisalima/backup_jenkins_config.git
  1. Edit common.sh and change the environment variables to suit your own configuration. I added some examples to get you started. Don't forget to generate the keys that you are going to use using ssh-keygen, and to add them to your remote git repository.

  2. Login with the jenkins user, and run:

source backup_jenkins_config/prepare_jenkins_backup.sh

What this script does is to prepare an ssh identity for your git repository, create a backup directory and initialize an empty git repository there.

  1. Just for the sake of it, run your first backup to see whether everything is allright :)
source backup_jenkins_config/backup_jenkins.sh

Recurrent backups

You can execute backup_jenkins.sh regularly using a cron task or just create a jenkins job to do it :) My jenkins job simply executes the script as follows:

bash /var/lib/jenkins/backup_jenkins_config/backup_jenkins.sh

And is set to run every day around midnight (depending on load):

H 00 * * *

Disclaimer

I tested this in an Ubuntu Linux distribution, if you'd like to tweak for any other use just fork the repo at will, it's MIT License.