How to Move jenkins with all plugin,Jobs and all other configuration to another server in cloud - jenkins

Need expert help on this.I have a task to move on premises jenkins to GCP Cloud server and need exact replica of the Jenkins.Can someone help me on this.I want all plugins ,configuration and jobs to be present in new GCP machine and it should be exact replica of the on premise jenkins server so that we can shut down the on premise machine.

I got this instructions that seems to be correct:
Following the Jenkins wiki, you'll have to:
Install a fresh Jenkins instance on the new server
Be sure the old and the new Jenkins instances are stopped
Archive all the content of the JENKINS_HOME of the old Jenkins
instance
Extract the archive into the new JENKINS_HOME directory
Launch the new Jenkins instance
Do not forget to change documentation/links to your new instance of
Jenkins :)
Do not forget to change the owner of the new Jenkins files : chown -R
jenkins:jenkins $JENKINS_HOME
JENKINS_HOME is by default located in ~/.jenkins on a Linux installation, yet to exactly find where it is located, go on the http://your_jenkins_url/configure page and check the value of the first parameter: Home directory; this is the JENKINS_HOME.
You can review the details in this link, an also this link with 3 methods that you could use.

Related

Upgrade Jenkins CI withourt losing User/Job Config

I would like to upgrade Jenkins to the latest version without losing job/user configuration.
From looking through various posts the answer seems to be to replace the jenkins war directory.
I did this and although the new version seems to be in place the about dialogue still has the original version,
I think this is because the versionnumber is held in a config file outside of the war folder.
Is there a better method to upgrade.
I have the best practice with replacing jenkins.war file, content of the folder should got extracted from war file during server startup (automatically).
All configuration is stored as files in jenkins home directory.
jobs in subfolder jobs, users in users etc.
So if you will replace war file, you will dont loose the configuration or content.
You can check this for better info, looks for "Install the New Jenkins War File
"
I am sharing my experience here, as this would definitely help someone. We were on jenkins 2.138.3 and wanted to upgrade to 2.235.5 version. Now the issue we were facing is our users were getting deleted when we tried to restore the users folder from the backup of old jenkins.
Root Cause: In the jenkins upgrade the mechanism to store the users on the disk is changed. This is verified by seeing the users//config.xml of both old and new jenkins.
The first problem we faced starting the jenkins is below error
java.nio.file.DirectoryNotEmptyException: /Users/jenkins/<username>
The reason being, in the upgraded jenkins the username folder is changed. for e.g. if your username is admin then in new jenkins the folder would be something like $JENKINS_HOME/users/admin_6635238516816951048/ instead of $JENKINS_HOME/users/admin/ and this mapping is captured separately in a file
$JENKINS_HOME/users/users.xml where a sample entry would look like
<entry>
<string>admin_6635238516816951048</string>
<string>admin_6635238516816951048</string>
</entry>
Here the first String is your username and second is the folder where config.xml for your user should exists.
In our old jenkins this folder structure is not available and hence we see the error
java.nio.file.DirectoryNotEmptyException: /Users/jenkins/<username>
So, what are the steps to migrate users properly so existing credentials can be used.
Once the new jenkins war is deployed on the new jenkins, stop the jenkins.
If there exists a users.xml file in $JENKINS_HOME/users/users.xml, delete it or rename it so jenkins wont look for the new folder structure
Restore your users folder from old jenkins to new jenkins at $JENKINS_HOME location. So all your users should appear in new jenkins # $JENKINS_HOME/users folder
Start the jenkins service.
And you should be able to login with your old jenkins user's credentials.
The detailed explanation can be found at
https://www.jenkins.io/doc/upgrade-guide/2.138/#SECURITY-1072

How do I move Jenkins from one server to another?

I need to move Jenkins version 2.32 from Server A to Jenkins 2.72.1 Server B.
Both server have ubuntu 16.04.3
I could not install any plugin and take back up in Server A due to memory issues. Is there any way that I could achieve this?
Copy all the files in your JENKINS_HOME directory over to the new server.
Point JENKINS_HOME on the new server at the new directory.
Copy the Jenkins war file (or your servlet container setup if you have one) over to the new machine and start it up.
All Jenkins settings, jobs, plugins, config, etc. live in JENKINS_HOME. You just need a copy of it to start it elsewhere.
Following JENKINS/Administering+Jenkins, you still need to make a backup of JENKINS_HOME.
See also How to Migrate a Jenkins Job to New Jenkins Server
If you want to exclude the plugins for space issue, you can list them in a text file, and reload them with a groovy script.

Jenkins service won't start after backup

My organization needs to make backups of our heavily customized Jenkins instance. After doing some research on different methods for backing up Jenkins, we decided to go the route of copying the whole Jenkins directory using xcopy and then moving the backup to a new instance on a different machine. (The reason for using xcopy is that its the only way to preserve they symbolic link files within each job.)
Here's the steps I have taken:
A batch file uses xcopy to copy the entire D:\Jenkins directory on a nightly basis from the old machine
I install a fresh instance of Jenkins on a new server
I stop the Jenkins service from running
I delete the current Jenkins directory in the new machine and then xcopy the backup in its place
I attempt to start the Jenkins service and I am met with the following error:
The Jenkins service on Local Computer started and then stopped. Some
services stop automatically if they are not in use by other services
or programs.
I have tried running jenkins.war from the command line and that just causes a Jenkins instance to start up that doesn't register as a windows service, and I cannot login to (even after disabling useSecurity), and looks like it doesn't have our modifications present.
I have also tried clearing the application log and that did not help.
I am not sure how to get the Jenkins service up and running.
The one folder you need to backup is the one referenced by the environment variable JENKINS_HOME
It is best to keep that folder separate from the installation folder like C:\Program Files (x86)\jenkins.
Then I prefer using a tomcat instance, and copy the jenkins.war in it: it is easier to upgrade:
Simply overwrite your jenkins.war with the new version. Tomcat should automatically redeploy the application.

Exporting Jenkins exact settings / plugins from server 1 to server 2

I read about archiving JENKINS_HOME in the wiki
(https://wiki.jenkins-ci.org/display/JENKINS/Administering+Jenkins)
but didnt exactly tell me how to archive it, was looking for any type of assistance
I found this
How to move Jenkins from one PC to another?
which is great but have some open ended questions and cant comment due to my low rank.
thanks!
You just have to zip your Jenkins home folder and copy it to the new server (the new Jenkins instance must be stopped).
Next, starts the new Jenkins instance and check you can access the new URL.
Once Jenkins is started, go to the Manage Jenkins/Configure system menu and update the Jenkins URL:
It should be enough to move your Jenkins stuff to the new server.

Jenkins runs as root instead of Jenkins

I have a newly installed jenkins server running on my computer, and am having some issues related to permissions.
It seems that jenkins creates the workspace directory as the root user, and then of course all task (including even pulling from the repository) fail, because they do not have permissions to modify the directory
Have a look at the Started-By Environment Variable plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Started-By+Environment+Variable+Plugin
If you are just asking how to set up Jenkins to run under a different user in Linux it depends on how you installed it. Have a look at https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins for different setup options. I had a look at Installing Jenkins as a Unix daemon and at step 7 you need to setup a configuration file. Change the last line in that file (RUN_AS_USER=jenkins) to contain the user of your choice.

Resources