Migrating Jenkins to a new server

Jenkins logo (license: CC BY-SA 3.0)

After getting annoyed with the outdated packages on CentOS 5.6 I decided to migrate my Jenkins server to Ubuntu 16.04.

It was surprisingly straightforward:

  1. Backup the old Jenkins server in case something goes wrong.

  2. Setup a new server with Ubuntu 16.04 (guide).
    You can get $10 credit to run a server on DigitalOcean by using my referral link.

  3. Install Jenkins on the new server (guide):

     wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
     sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
     sudo apt-get update
     sudo apt-get install jenkins
  4. Sync the /var/lib/jenkins folder on the old server to the new one by running this command from the new Jenkins server (where is the old server’s IP and user is the old server’s ssh user):

     rsync -av [email protected]:/var/lib/jenkins /var/lib --exclude workspace/ --exclude cache/ --exclude .cache/ --exclude node_modules/ --exclude .npm/

    I excluded some directories to speed up the process but thats up to you. Check out this guide for more on using rsync remotely.

  5. Restart Jenkins:

     systemctl restart jenkins
  6. Done!