Skip to content

Jenkins - Server Maintenance

Regular maintenance is crucial for a stable and performant Jenkins environment. This includes monitoring, cleanup, and ensuring reliable backups.

  • Load Statistics: Check Manage Jenkins → Load Statistics regularly to monitor queue length and executor usage. High queue times or consistently maxed-out executors indicate a need for more agents or more powerful hardware.
  • System Logs: Review logs (Manage Jenkins → System Log) for errors or warnings that might indicate underlying problems.
  • Monitoring Plugin: Install the ‘Monitoring’ plugin to integrate Jenkins metrics (CPU, memory, disk, executors, queue) with monitoring systems like Prometheus and visualize them in dashboards like Grafana. This provides much deeper insights.
  • Disk Space: Actively monitor the disk usage of JENKINS_HOME, especially the jobs (build history) and artifacts directories. Running out of disk space is a common cause of Jenkins failures.
  • Discard Old Builds: Configure jobs (especially high-frequency ones) to automatically discard old build records and artifacts. This is essential for managing disk space. In Pipeline jobs, use the options directive:
  • options { buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '5')) }
  • In Freestyle jobs, use the ‘Discard old builds’ setting in the job configuration.
  • Workspace Cleanup: Use workspace cleanup plugins (like ‘Workspace Cleanup Plugin’) or cleanWs() step in Pipelines to remove workspace contents before or after builds, preventing leftover files from causing issues or consuming excessive disk space.
  • Archive Necessary Artifacts: Only archive artifacts that are genuinely needed for later use or deployment. Avoid archiving large intermediate files.
  • Regular Restarts: While Jenkins can run for long periods, occasional scheduled restarts (e.g., during maintenance windows) can help clear memory leaks or apply pending updates.
  • Plugin Maintenance: Regularly review installed plugins (Manage Jenkins → Plugins → Installed). Uninstall unused plugins to reduce overhead and potential security vulnerabilities. Keep installed plugins updated.

This is covered in detail in the ‘Backup Strategies’ chapter. Key points include:

  • Identify Critical Data: Primarily the JENKINS_HOME directory.
  • Choose a Strategy: Full JENKINS_HOME backup, using backup plugins (like ThinBackup), leveraging Configuration as Code (JCasC, Job DSL, Jenkinsfile), or a combination.
  • Schedule Regularly: Perform backups frequently (e.g., daily).
  • Store Securely: Keep backups in a separate, secure location.
  • Test Restores: Periodically test your restore process to ensure it works.

If Jenkins is installed as a service (common with native packages or Docker setups):

  • Starting/Stopping/Restarting: Use standard service management commands:
  • sudo systemctl start jenkins
  • sudo systemctl stop jenkins
  • sudo systemctl restart jenkins
  • sudo systemctl status jenkins
  • (Commands may vary slightly based on OS/init system, e.g., service jenkins start)
  • Configuration: Service configuration (like JAVA_HOME, Jenkins arguments, JENKINS_HOME location, port) is often managed in a system configuration file (e.g., /etc/default/jenkins or /etc/sysconfig/jenkins on Linux).

While service management is preferred, these URLs can sometimes be used for quick actions (require appropriate permissions):

  • http://<jenkins_url>/safeExit - Prevent new builds from starting.
  • http://<jenkins_url>/safeRestart - Restart Jenkins once running builds complete.
  • http://<jenkins_url>/exit - Force shutdown immediately.
  • http://<jenkins_url>/restart - Force restart immediately.
  • http://<jenkins_url>/reload - Reload configuration from disk.

Consistent maintenance ensures your Jenkins instance remains a reliable foundation for your CI/CD pipelines.