12/6/2024 • VirtueCloud

Jenkins is a cornerstone of many CI/CD pipelines, enabling seamless automation for software development and deployment. But as infrastructure evolves, migrating Jenkins from one virtual machine (VM) to another becomes inevitable—for scalability, resource optimization, or upgrading environments.
This guide provides a step-by-step process for migrating Jenkins while preserving all jobs, configurations, and plugins. The approach ensures minimal downtime, full data integrity, and no service conflicts. Whether you're scaling your Jenkins setup or transitioning to a new environment, this migration guide has you covered.
This document details how to migrate a Jenkins server between VMs while ensuring:
Set Up the New VM
Objective: Replicate the environment on the new VM to avoid compatibility issues.
sudo apt install openjdk-17-jdk -y sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins sudo systemctl stop jenkins # On both VMs Backup Jenkins Data to Azure Storage
Objective: Safely transfer the Jenkins data from the old VM to the new one via Azure Storage.
tar -czvf jenkins_backup.tar.gz /var/lib/jenkins az storage blob upload \
--account-name <your_storage_account> \
--container-name <container> \
--file jenkins_backup.tar.gz \
--name jenkins_backup.tar.gz Download Jenkins Data from Azure to the New VM
Objective: Restore the Jenkins data from Azure Storage to the new VM.
az storage blob download \
--account-name <your_storage_account> \
--container-name <container> \
--name jenkins_backup.tar.gz \
--file jenkins_backup.tar.gz \
--account-key <key> Extract Data on the New Jenkins Instance
Objective: Deploy the Jenkins data to the correct directory on the new VM.
sudo tar -xzvf jenkins_backup.tar.gz -C /var/lib/jenkinssudo chown -R jenkins:jenkins /var/lib/jenkins Start Jenkins on the New VM
Objective: Verify that the migration is successful.
sudo systemctl start jenkins ssh -i <path_to_your_key.pem> -L 8080:localhost:8080 <user>@<new_vm_ip_address>Verification:


By following these steps, you’ve successfully migrated Jenkins to a new VM with no data loss or service conflicts. Using Azure Storage for backup ensures data consistency and simplifies the migration process. This guide minimizes downtime, allowing your team to continue delivering with confidence.
Have you performed a Jenkins migration before? Share your experiences or tips in the comments below. If you found this guide helpful, feel free to share it with your network!
Related articles you might find interesting

Why platform teams are re-routing north-south traffic through the Kubernetes Gateway API, what HTTPRoute changes on the ground, and how to migrate without a big-bang rewrite.


Hassle-Free ECS: Terraform Automation + CI/CD Pipeline