问题
I am currently using Jenkins on my development PC. I installed it on my development PC, because I had limited knowledge on this tool; so I tested on it in my development PC. Now, I feel comfortable with Jenkins as my long term "partner" in the build process and would like to "move" this Jenkins to a dedicated server.
Before this I have done few builds and have the artifacts archived from each build. In particular, the build number is very important to me for version control.
How can I export all the Jenkins information from my current PC to my new server?
回答1:
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.
回答2:
In case your JENKINS_HOME directory is too large to copy, and all you need is to setup same Jobs, Jenkins Plugins and Jenkins configurations (and don't need old Job artifacts and reports), then you can use ThinBackup Plugin:
- Install ThinBackup on both the source and the target Jenkins servers
Configure Backup Directory on both (in Manage Jenkins --> ThinBackup --> Settings)
On Sourse Jenkins go to ThinBackup --> Backup Now
- Copy from Jenkins Source Backup directory to Jenkins Target Backup Directory
- On Target Jenkins go to ThinBackup --> Restore, and then restart Jenkins service.
If some Plugins or Jobs are missing, copy the backup content directly to the target JENKINS_HOME.
If you had user authentication on the source Jenkins, and now locked out on the target Jenkins, then edit Jenkins config.xml, set
<useSecurity>
to false, and restart Jenkins.
回答3:
This worked for me to move from Ubuntu 12.04 (Jenkins ver. 1.628) to Ubuntu 16.04 (Jenkins ver. 1.651.2). I first installed Jenkins from the repositories.
- Stop both Jenkins servers
Copy
JENKINS_HOME
(e.g. /var/lib/jenkins) from the old server to the new one. From a console in the new server:rsync -av username@old-server-IP:/var/lib/jenkins/ /var/lib/jenkins/
Start your new Jenkins server
You might not need this, but I had to
Manage Jenkins
andReload Configuration from Disk
.- Disconnect and connect all the slaves again.
- Check that in the
Configure System > Jenkins Location
, theJenkins URL
is correctly assigned to the new Jenkins server.
回答4:
Jenkins Server Automation:
Step 1:
Set up a repository to store the Jenkins home (jobs, configurations, plugins, etc.) in a GitLab local or on GitHub private repository and keep it updated regularly by pushing any new changes to Jenkins jobs, plugins, etc.
Step 2:
Configure a Puppet host-group/role for Jenkins that can be used to spin up new Jenkins servers. Do all the basic configuration in a Puppet recipe and make sure it installs the latest version of Jenkins and sets up a separate directory/mount for JENKINS_HOME
.
Step 3:
Spin up a new machine using the Jenkins-puppet configuration above. When everything is installed, grab/clone the Jenkins configuration from the Git repository to the Jenkins home direcotry and restart Jenkins.
Step 4:
Go to the Jenkins URL, Manage Jenkins → Manage Plugins and update all the plugins that require an update.
Done
You can use Docker Swarm or Kubernetes to auto-scale the slave nodes.
回答5:
Sometimes we may not have access to a Jenkins machine to copy a folder directly into another Jenkins instance. So I wrote a menu driven utility which uses Jenkins REST API calls to install plugins and jobs from one Jenkins instance to another.
For plugin migration:
- GET request:
{SOURCE_JENKINS_SERVER}/pluginManager/api/json?depth=1
will get you the list of plugins installed with their version. You can send a POST request with the following parameters to install these plugins.
final_url=`{DESTINATION_JENKINS_SERVER}/pluginManager/installNecessaryPlugins` data=`<jenkins><install plugin="{PLUGIN_NAME}@latest"/></jenkins>` (where, latest will fetch the latest version of the plugin_name) auth=`(destination_jenkins_username, destination_jenkins_password)` header=`{crumb_field:crumb_value,"Content-Type":"application/xml”}` (where crumb_field=Jenkins-Crumb and get crumb value using API call {DESTINATION_JENKINS_SERVER}/crumbIssuer/api/json
For job migration:
- You can get the list of jobs installed on {SOURCE_JENKINS_URL} using a REST call,
{SOURCE_JENKINS_URL}/view/All/api/json
- Then you can get each job config.xml file from the jobs on {SOURCE_JENKINS_URL} using the job URL
{SOURCE_JENKINS_URL}/job/{JOB_NAME}
. - Use this config.xml file to POST the content of the XML file on {DESTINATION_JENKINS_URL} and that will create a job on {DESTINATION_JENKINS_URL}.
I have created a menu-driven utility in Python which asks the user to start plugin or Jenkins migration and uses Jenkins REST API calls to do it.
You can refer the JenkinsMigration.docx from this URL jenkinsjenkinsmigrationjenkinsrestapi
来源:https://stackoverflow.com/questions/8724939/how-to-move-jenkins-from-one-pc-to-another