How to Upgrade Jenkins Safely and Easily
To upgrade
Jenkins, first back up your Jenkins data, then download the latest jenkins.war file from the official site and replace the old one. Restart the Jenkins service to apply the upgrade and verify the new version in the dashboard.Syntax
Upgrading Jenkins involves these main steps:
- Backup: Save your Jenkins home directory to keep your jobs and settings safe.
- Download: Get the latest
jenkins.warfile from the official Jenkins website. - Replace: Stop Jenkins, replace the old
jenkins.warwith the new one. - Restart: Start Jenkins again to load the new version.
bash
sudo systemctl stop jenkins
sudo cp /path/to/new/jenkins.war /usr/share/jenkins/jenkins.war
sudo systemctl start jenkinsExample
This example shows how to upgrade Jenkins on a Linux system using systemd service:
bash
sudo systemctl stop jenkins
wget https://get.jenkins.io/war-stable/latest/jenkins.war -O /tmp/jenkins.war
sudo cp /tmp/jenkins.war /usr/share/jenkins/jenkins.war
sudo systemctl start jenkins
sudo systemctl status jenkinsOutput
● jenkins.service - Jenkins Continuous Integration Server
Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2024-06-20 10:00:00 UTC; 10s ago
Main PID: 12345 (java)
Tasks: 25 (limit: 4915)
Memory: 150.0M
CGroup: /system.slice/jenkins.service
└─12345 /usr/bin/java -jar /usr/share/jenkins/jenkins.war
Common Pitfalls
- Not backing up: Always back up
$JENKINS_HOMEbefore upgrading to avoid data loss. - Using outdated plugins: Plugins may break after upgrade; update plugins from Jenkins dashboard.
- Skipping restart: Jenkins must be restarted to apply the new version.
- Wrong file path: Ensure you replace the correct
jenkins.warfile used by your Jenkins service.
bash
## Wrong way: replacing wrong file sudo cp /tmp/jenkins.war /home/user/jenkins.war ## Right way: replacing correct file sudo cp /tmp/jenkins.war /usr/share/jenkins/jenkins.war
Quick Reference
Summary tips for upgrading Jenkins:
- Always back up
$JENKINS_HOMEdirectory. - Download the latest stable
jenkins.warfrom jenkins.io. - Stop Jenkins service before replacing the war file.
- Restart Jenkins service after replacement.
- Check Jenkins version in the dashboard footer after upgrade.
Key Takeaways
Always back up your Jenkins data before upgrading to prevent data loss.
Download and replace the
jenkins.war file with the latest stable version.Stop Jenkins service before upgrading and restart it afterward to apply changes.
Update plugins after upgrading Jenkins to avoid compatibility issues.
Verify the Jenkins version in the dashboard to confirm a successful upgrade.