Jenkins Data Storage: File System Locations and MySQL Integration Guide


1 views

Jenkins stores its configuration and build data primarily in the file system by default. The root directory (commonly called JENKINS_HOME) contains all critical data:


/var/lib/jenkins/ (typical default on Ubuntu)
  ├── jobs/          # Job configurations and build artifacts
  ├── plugins/       # Installed plugins
  ├── users/         # User account information
  ├── workspace/     # Checked-out source code
  ├── config.xml     # Global configuration
  └── *.xml          # Other system configurations

You can modify the storage location by setting the environment variable before starting Jenkins:


# In /etc/default/jenkins (Ubuntu/Debian):
JENKINS_HOME="/opt/jenkins_data"

# Or when running manually:
java -DJENKINS_HOME=/path/to/storage -jar jenkins.war

While Jenkins doesn't natively support RDBMS for core data storage, you have several options:

1. Using MySQL for Job Configuration (via ThinBackup Plugin)

The ThinBackup plugin can export configurations to MySQL:


# Configuration in Jenkins → Manage Jenkins → ThinBackup
Backup Storage Directory: /jenkins_backups
Database Configuration:
  JDBC URL: jdbc:mysql://localhost:3306/jenkins_backup
  Username: jenkins_user
  Password: ********
  Table Name: config_backups

2. Using Database for Build History (via SQL Plus Plugin)

The Database SQLPlus Plugin enables storing build results in databases:


// Pipeline example storing build results to MySQL
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'make'
            }
            post {
                success {
                    sqlplus(
                        credentialsId: 'mysql-creds',
                        database: 'jenkins_stats',
                        script: """
                            INSERT INTO build_results 
                            VALUES (${env.BUILD_NUMBER}, 'SUCCESS', NOW());
                        """
                    )
                }
            }
        }
    }
}

For enterprise deployments, consider these architectural patterns:


1. NFS-mounted JENKINS_HOME for shared storage
2. Periodic rsync to backup servers
3. Containerized Jenkins with persistent volumes
4. Cloud storage backend (S3, GCS) for build artifacts
  • File system storage provides best performance for Jenkins core operations
  • Database integration works best for specific use cases (reporting, audit)
  • Always maintain regular backups of JENKINS_HOME
  • For HA setups, consider Jenkins Configuration as Code (JCasC) patterns

When you install Jenkins on Ubuntu or any other Linux distribution, it stores all configuration data, build histories, and job details in its home directory by default. The typical location is:

/var/lib/jenkins

This directory contains several important subdirectories:

  • jobs/ - Contains configuration and build records for each job
  • plugins/ - Stores installed plugins and their configurations
  • users/ - User account information and preferences
  • workspace/ - Working directories for jobs

While Jenkins primarily uses file-based storage, you can configure it to work with databases through plugins. MySQL integration is possible using the Database plugin.

Here's how to set up MySQL as a backend for Jenkins:

  1. Install MySQL server and client packages:
  2. sudo apt-get install mysql-server mysql-client
    
  3. Create a Jenkins database and user:
  4. CREATE DATABASE jenkins;
    CREATE USER 'jenkins'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON jenkins.* TO 'jenkins'@'localhost';
    FLUSH PRIVILEGES;
    
  5. Install the Database plugin in Jenkins:
  6. Manage Jenkins → Manage Plugins → Available → Search "Database" → Install
    
  7. Configure the database connection in Jenkins:

Example configuration in config.xml:

<database>
  <driver>com.mysql.jdbc.Driver</driver>
  <url>jdbc:mysql://localhost:3306/jenkins</url>
  <username>jenkins</username>
  <password>password</password>
</database>

While database integration is possible, note that:

  • Not all Jenkins data can be moved to a database (build artifacts remain on disk)
  • Some plugins might not support database storage
  • Performance impact should be tested for your specific workload

For better scalability, consider:

  1. Mounting the Jenkins home directory on network storage
  2. Using cloud storage solutions like AWS EFS
  3. Implementing regular backups of the /var/lib/jenkins directory