Brief Introduction
Virtual machines have many benefits, not only save hardware resources, but also can quickly switch the system environment, obviously in software development plays a great role.
The management of the virtual machine environment is mentioned in chapter 11th (11.7.1) of "continuous delivery". The following figure
It describes the need for a variety of servers to test an application in your continuous integrated Jenkins CI Server (hereinafter referred to as Jenkins). We can quickly from the virtual machine VMM Template Library, start the various types of virtual machines needed, rather than each reinstall (time-saving), complete the test, generate a report, also quickly disappear (save money).
Let's take a look at a beautiful implementation vagrant+jenkins implementation techniques. Basic Knowledge Vagrant
Different virtual machine technology (VIRTUALBOX,VMWARE,XEN/KVM, etc.) may be managed in different ways, vagrant is the front-end of VirtualBox, it simplifies the operation of VirtualBox virtual machine, and increased support for automation (provisioning) Puppet/chef is not described in detail here. Vagrant Introduction has been very detailed, there is a blog can also be used for reference.
All you need to know is the next few commands.
$ cd UBUNTU1104-VM # Enter existing Ubuntu 11.04 virtual machine directory
$ vagrant Up # start Ubuntu virtual machine
$ vagrant ssh-c "pwd"
/home/vagran T
$ vagrant Halt # Stop virtual machine
Jenkins CI
Jenkins is one of the most common continuous integration servers that can be run individually or on a Web server.
It is not a good way to start a task directly (Jenkins job) to invoke vagrant to operate a virtual machine, because the permissions of the user starting the Jenkins (such as Tomcat) are relatively small to prevent the task from being manipulated incorrectly.
Luckily Jenkins has a great master-slave mode (master/slave) to solve. Project Construction Establish vagrant users
It is best to create a vagrant user with a vagrant user environment on one machine (which can not be with the Jenkins host).
Because there is no password access, so to match the SSH environment, we can reuse the vagrant virtual machine public and private key, such as the following identityfile is the private key.
vagrant@host:~/vm/ubuntu1104$ vagrant ssh_config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
userknownhostsfile/dev/null
stricthostkeychecking no
passwordauthentication no
identityfile /var/lib/gems/1.8/gems/vagrant-0.8.7/keys/vagrant
identitiesonly Yes
Copy the public-private key to the vagrant user's. SSH directory.
vagrant@host:~$ mkdir. SSH
vagrant@host:~$ cp/var/lib/gems/1.8/gems/vagrant-0.8.7/keys/vagrant. Ssh/id_rsa
vagrant@host:~$ chmod ssh/id_rsa
vagrant@host:~$ cat/var/lib/gems/1.8/gems/vagrant-0.8.7/keys/ Vagrant.pub >> Ssh/authorized_keys
Jenkins Slave Settings
Then go to the Jenkins host's system Management-> Management node-> create a new node to increase the Vagrant Virtual machine node, as shown below.
In the example, the Vagrant node and the Jenkins host are on a machine, so it is localhost, the private key is configured, and the label is set to VAGRANT-VM Jenkins task settings
Now you can set up a new task, select the free Style (freestyle), the following figure
Limit it to VAGRANT-VM to execute, and it will trigger the start of Jenkins from the Machine (slave).
Then set up a build content, that is, start the virtual machine, execute the command (the real situation will be installed with puppet, and test).
Finally, you can let it run. Summary
This article is a brief talk about the management of virtual machines in the Jenkins of a scheme, automated installation puppet did not mention, you can try. In addition vagrant created virtual machine also did not talk about, generally can use Veewee this software to complete, have time to talk next. reference Larry's English blog: http://codeslife.com/2011/10/21/make-ci-easier-with-jenkins-ci-and-vagrant/ StackOverflow Question discussion: How to combine vagrant with Jenkins for perfect continuous integration?
Reprinted from continuous delivery.