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

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.

Related

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

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.

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

Jenkins Error: org.xmlpull.v1.XmlPullParserException

I have installed successfully Jenkins after the next day, I have tried to reopen by restarting the Service:Jenkins and got this error.
Should I reinstall Jenkins ?
Thank you.
To get rid of the lockout follow these steps to manually change the version, which could just be back to your old working version.
Stop the Jenkins windows service
Rename war directory to war.bak
Rename jenkins.war to jenkins.war.bak
Get a new war file from https://updates.jenkins.io/download/war/
Copy new jenkins.war into jenkins directory
Start Jenkins windows service
Observe creation of war directory which will now contain contents of jenkins.war archive
Navigate to jenkins home page, at which point you will be informed
that Jenkins is preparing your installation
Once complete, test your
existing jobs to verify compatability
Navigate to 'Manage Jenkins'
via the menu and Action any notifications displayed - plugins, data
format conversions etc.
Delete jenkins.war.bak file and war.bak folder
After following those steps you will be able to get back into Jenkins, you might have other version issues with plug-ins but at least you can get back in and not lose everything. Also always put your pipeline scripts in source control and use a back up plug in for Jenkins.

How to deploy java application(war) to EC2 using jenkins?

I am setting up develop environment for java project.
And my team decide to use Jenkins for CI, and AWS EC2(linux) for server.
I succeeded to make an war file by jenkins job.
But, I can't find a way how to copy war file to EC2, and restart tomcat server on EC2.
I googled about it using "jenkins ec2 deploy", but in fail.
somebody help me!
Step 1. Install Jenkins plugin
Open your favorite browser and navigate to Jenkins. Log in and select “Manage Jenkins” followed by “Manage Plugins”. Select the “Available” tab, locate the “Deploy to container” plugin and install it.
Step 2. Edit tomcat-users.xml
In order for Tomcat to accept remote deployments, you have to add a user with the role manager-script. To do so, edit the file ../conf/tomcat-users.xml and add the following line:
<user username="deployer" password="deployer" roles="manager-script" />
Step 3. Edit the Jenkins job
Back in Jenkins, go to your job and select “Configure”. Next, scroll down to the bottom of the page to the “Post-build Actions”. Select the option “Deploy war/ear to a container” from the “Add post-build action” dropdown button. Fill in the new fields.
Step 4. Run the Job project and verify the end results
Schedule a build for your job in Jenkins. If you check out the log file you should see one or more lines near the end indicating that the war file has been deployed.
If you check the logfiles in Tomcat (catalina.out) you should also see that your application has been succesfully deployed.
Lastly, if you point your browser to the URL and context path you’ve specified in the job configuration in Jenkins (e.g., http://your-server:8080/mywebapp), you should be able to open your freshly deployed application.
Credits to Jdev.it
More info can be found here
With EC2 (or any other deployment practice too), first determine your production servers are going to be mutable or immutable.
[Mutable]
The servers will be running forever, and you perform on-going updates as explained in the blogpost mentioned above (elizabetht) for Java war, or many other ways for different languages/platform.
[Immutable]
The servers are re-created (vs. upgraded) by automation mechanism such as scripting, or using config. mgmt tools like Puppet/Chef/Ansible or vendor specific initialization mechanism like AWS Userdata/Docker dockerfile/Vagrant vagrantfile, or using many other provisioning tools.
Generally speaking databases or queues should be Mutable category, and all other compute nodes are better be Immutable category. The benefits of Immutable category are a lot including easy HA, disaster recovery and also enables Blue/Green deployment and much more.

Where is the Jenkins working directory located?

Situation:
I installed Jenkins on my vserver and setup a "freestyle pipeline". I connected it via webhook push to my github which works (when I push to the repository, a new build job is started in jenkins).
Problem:
I can't seem to find the working directory where the git pull is executed in. I already searched for answers and many people say $JENKINS_HOME, but echo $JENKINS_HOMEreturns a blank line for me. Did I do anything wrong or where is my project then? Also, can I set the path to where the repository is pulled to a custom path (say /root/myprojectname)?
EDIT:
I can see the workspace in Jenkins webuserinterface but I can't find the corresponding folder on the vservers drive.
Did you check in /var/lib/jenkins. By default the jenkins home directory lies there as well in case of linux servers. It should also show you the home directory by browsing Manage Jenkins--> Configure System

Resources