<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rohil Mogal</title>
    <description>The latest articles on DEV Community by Rohil Mogal (@rohil_mogal).</description>
    <link>https://dev.to/rohil_mogal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3126385%2F27e6eb8d-4b40-4719-a710-acf7d58fc53d.png</url>
      <title>DEV Community: Rohil Mogal</title>
      <link>https://dev.to/rohil_mogal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rohil_mogal"/>
    <language>en</language>
    <item>
      <title>Seamless Jenkins Migration Across Platforms Using Docker Compose</title>
      <dc:creator>Rohil Mogal</dc:creator>
      <pubDate>Tue, 06 May 2025 04:52:08 +0000</pubDate>
      <link>https://dev.to/rohil_mogal/seamless-jenkins-migration-across-platforms-using-docker-compose-14a0</link>
      <guid>https://dev.to/rohil_mogal/seamless-jenkins-migration-across-platforms-using-docker-compose-14a0</guid>
      <description>&lt;h2&gt;
  
  
  Migrate Jenkins from Linux VM to macOS (Plain Installation)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Jenkins Backup&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Find your current JENKINS_HOME&lt;br&gt;
(If unsure, you can check it inside Jenkins UI → Manage Jenkins → System Information → search for JENKINS_HOME.) e.g. /var/lib/jenkins&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Backup Jenkins home&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo tar -czvf jenkins_backup.tar.gz /var/lib/jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Transfer the Backup to Your macOS Machine&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now this really depends on how you want to copy this data. Either SCP, USB, etc. I used traditional USB stick to copy this data to my Mac device.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Install Jenkins on macOS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install jenkins-lts

brew services start jenkins-lts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, Jenkins will use /Users//.jenkins as the JENKINS_HOME.&lt;/p&gt;

&lt;p&gt;I faced an issue where Jenkins dint really start as it was not able to discover JAVA_HOME env upon running above command. Best way to get rid of this was to run this without services command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jenkins-lts 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That the entire 2 words command to start Jenkins with all the env variables preserved and available for jenkins to use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Replace macOS Jenkins Data with the Backup&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stop Jenkins on macOS:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew services stop jenkins-lts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR &lt;br&gt;
Command + C to Stop if you ran&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jenkins-lts 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Extract the backup and replace Jenkins home
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~
tar -xzvf jenkins_backup.tar.gz
mv ~/.jenkins ~/.jenkins.backup   # Backup current empty Jenkins home
mv var/lib/jenkins ~/.jenkins     # Use Linux Jenkins data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Fix permissions
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo chown -R $(whoami) ~/.jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Start Jenkins again
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew services start jenkins-lts 
#OR
jenkins-lts

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Verify&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Visit &lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt; on your browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Restore Jenkins from Backup using Docker Compose
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Jenkins Backup&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Find your current JENKINS_HOME&lt;br&gt;
(If unsure, you can check it inside Jenkins UI → Manage Jenkins → System Information → search for JENKINS_HOME.) e.g. /var/lib/jenkins&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Backup Jenkins home&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo tar -czvf jenkins_backup.tar.gz /var/lib/jenkins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Transfer the Backup to Your macOS Machine&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now this really depends on how you want to copy this data. Either SCP, USB, etc. I used traditional USB stick to copy this data to my Mac device.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Extract Jenkins Backup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a working directory in your choice of OS (Linux, MacOS)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir ${PWD}/jenkins_home
tar -xzvf jenkins_backup.tar.gz -C ${PWD}/jenkins_home --strip-components=1

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Create the docker-compose.yml File&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3'

services:
  jenkins:
    image: jenkins/jenkins:lts
    container_name: jenkins
    ports:
      - "8080:8080"
      - "50000:50000"
    volumes:
      - ./jenkins_home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock  # Optional: if Jenkins needs to run Docker
    restart: unless-stopped

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Start Jenkins with Docker Compose&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up -d

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6: Verify&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Visit &lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt; on your browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Known Issues - Admin Login Issue
&lt;/h2&gt;

&lt;p&gt;Even after doing everything correctly, you might not able to login with admin or user credentials even though its correct and worked on earlier. Reason being whenever you create a user creds in Jenkins it encrypt it and might not be able to decrypt it. Fastest way to recover from this &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution 1: Delete Admin User&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm -rf jenkins_home/users/admin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart Jenkins after this and it will promt to create new admin user&lt;/p&gt;

&lt;p&gt;Solution 2: Alter Admin Hashed Password&lt;/p&gt;

&lt;p&gt;Ideally all the users are stored in /var/lib/jenkins/users/&lt;br&gt;
You might see a folder with admin prefix. e.g. admin_13844028951691835221&lt;br&gt;
Locate config.xml file inside the admin folder and change the below line&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;hudson.security.HudsonPrivateSecurityRealm_-Details&amp;gt;
      &amp;lt;passwordHash&amp;gt;#jbcrypt:$2a$10$1me96JIU604I.q19wwgJTeqNJUKwZAuP11brUjk6VJTBfRuAYixxe&amp;lt;/passwordHash&amp;gt;
    &amp;lt;/hudson.security.HudsonPrivateSecurityRealm_-Details&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a new hash with the password you desire. You can use the below link to create a hash password&lt;br&gt;
&lt;a href="https://bcrypt-generator.com/" rel="noopener noreferrer"&gt;https://bcrypt-generator.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Replace the old hash value with the new hash you just created. Restart Jenkins and try to login with new password.&lt;/p&gt;

&lt;p&gt;Just like Magic !!!! (Yeah I know, petty tricks but it works) &lt;/p&gt;

</description>
      <category>devops</category>
      <category>jenkins</category>
      <category>docker</category>
      <category>kubernetes</category>
    </item>
  </channel>
</rss>
