JENKINS+MAVEN+SVN quickly build a continuous integration environment

Source: Internet
Author: User

Http://www.cnblogs.com/sunzhenchao/archive/2013/01/30/2883289.html
http://blog.csdn.net/pein_zero/article/details/52597615

The first thing to do is to install SVN and maven on the server.

Preface before installing, I would like to explain the purpose of this article, a continuous integration tool for Jenkins, It can do a lot of things, one of the main functions is to simplify the deployment process     think back to our release process: 1. Package The project locally 2. Transfer to server via FTP and other tools 3. Close Tomcat and put the packaged items in the WebApp directory 4. Start Tomcat   If you do this every time, it's not only slow, it's also easy to make mistakes.     with Jenkins, the release process can be: 1. Users click on a button on Jenkins to publish 2.jenkins receive the Publish command 3.jenkins Download source code down from SVN 4.jenkins is packaged according to the MVN command you set 5.jenkins Transfer your packaged war project to the WebApps directory of Tomcat 6.tomcat Boot   for programmers, just do two things: 1. Configure the deployment process for a project on Jenkins 2. Click on a project's deploy button on Jenkins to deploy it one -buttonIn fact, the configuration is often done only once, the rest of the time, you just one-click deployment can be First, install Jenkins   1. Download Jenkins   first go to Jenkins official website to download Jenkins, the official website has two download options:   if it is used by the company, it is recommended to select the left. if it is for personal use, you can use the right   if you want to download the installation version, click the drop-down arrow, Windows is Exe,linux is the RPM package               If you want to download the war package, click Directly, do not click the drop-down arrow, I downloaded the war package  
    2. Set Jenkins_home after the download is finished, it is best to set the Jenkins_home first; Otherwise, for Windows systems, it will be installed on the C drive by default the Linux system is not clear where the default is But after you set it up, it's going to be where you want it to be, to generate Jenkins stuff. about setting home, as with setting up Java_home, Windows does not say, Linux, as with Java, modify the/etc/profie file can be   3. Start Jenkins with the war pack, as with any other project, put it under Tomcat and start Tomcat. using the installation package of the classmate, Windows, start in the service, and the MySQL, Oralce service startup is the same, the Linux students themselves study   When you start Tomcat, you get an error:
              This is because Jenkins does not know when the HTTP access has been changed to HTTPS, but the war package configuration file has not changed,                but this does not affect your startup and access, in a later operation, we will change the
4 . Visit Jenkins
enter Http://127.0.0.1:8080/jenkins in the browser, go to Jenkins, specific IP and port, according to your actual environment to                the first is to enter the initial password, this is prompted, follow the prompts to find the file, find the password, input can the next step is to enter the plugin selection page:               
I chose skip Plugin installations, I skipped the initialization of the plugin, in fact, I do not want to skip. If you don't skip it, Jenkins has an option that lets you install the recommended plugin.                but because of the exception that was started, Jenkins changed the address of the fetch plugin from HTTP to HTTPS, and the war package did not change               When you click on the "Recommended plugin download" button, it doesn't work.                so we can just skip it, and we'll install the plug-in later.                Next is to create an admin user, note that after the creation, the previous admin account will disappear, the original password file is no longer exist               So, the user name you enter here, can be the admin                 After the creation is complete, the installation and startup of Jenkins is completed. Second, install the plug-in   1. Modify the connection address                 Left click on System Management, right Select management plug-in,               

              Select the Advanced panel:               

              Pull down, change HTTP to HTTPS, click "Submit", then click "Get Now"  

       2. Installing the MAVEN Plugin               Why install the Maven plugin? You click the new, is not the following figure               

If you've used someone else's Jenkins before, the old version here has a Maven 2/3 project, and the new version here is also the option to create a MAVEN project. you didn't, because you didn't install the Maven plugin, so install the Maven plugin so you can build a Maven project or, System management--plug-in management--optional plugins this time, you should be able to see the list of optional plugins, because before the operation, we have correctly modified the URL of the site   in the filter, enter MAVEN to find MAVEN integration plugins:                              Tick, install, wait some time later, you will find the installation error               
              It doesn't matter, see details               

              The general meaning is that the signature verification of the file is not correct, regardless of it, pay attention to the red path. Find this file and open it               
               Copy this path and put it in your browser to download the plugin.                My advice is to build a Jenkins directory on the MAVEN plugin locally and put Maven-related plugins in this directory                            
               Several other plugins also find the corresponding file, find the URL, download                Then manually upload the plugin. Upload plugin in: System Management--management plugin--advanced, you can see the place to upload plugins               
               Note that the order of uploads is the same as the order of the error, because these plugins are dependent on the sequencing, but even if the order is wrong, it does not matter, the system will prompt you:               
               Once the installation is complete, you can create a MAVEN project.               
       3. Install the SVN plugin                The SVN plugin is installed in the same way as the Maven plugin, and the SVN plugin's name is: Subversion plug-in after installing SVN, you are in the new project, source control here is a more Subversion option               
       4. Install the Deploy plugin                The Deploy plugin is installed in the same way as the Maven plugin, and the Deploy plugin is named: Deploy to Container Plugin
After you install the SVN, when you create a new project, after the build action here, the drop-down option will be more than a deploy war/ear to a container               


Iii. Creating a Build project   1.Configuring the JDK and maven before you create a project, you configure the JDK and maven Click, System Management--global Tool Configuration                  
               In the following diagram configuration, you can               
                              
              Just follow the way I did, write your own configuration and you can
2 . Create a Build project                No more nonsense, just follow the configuration I have.                  
              Here is the explanation,                             The first one is the SVN address, The second one is Credentials, which is actually your SVN account and password, There must be no one here at first, I need you to click Add               
               Just add your SVN account and password.               
              
                              
              
              
Here's what you need to do, post-build, copy the war package through the MAVEN command into Tomcat, This requires Tomcat to turn on the hot deployment, which is to add the Tomcat user password to Tomcat-users.xml in Tomcat's conf directory.               

above this paragraph, you can completely copy, of course, the user name and password according to your own needs to configure the username and password set here must be the same as the manager user name and password that you filled in the deploy to Cotainer plate above. In addition, about the Deploy plugin, although it is written to support only to tomcat7.x, but in fact, 8.x Tomcat it can still support               
        3 . Start building
               now that a build project has been created, just click the Build button to try it out:                                            

change: The above approach, the final deployment is the use of Tomcat hot deployment, this approach has a great disadvantage, that is, after many releases, memory will continue to rise. so that's not a good way. a better way is to use a script, shut Tomcat down, then remove the old deployment application under WebApps, put the new war package back, and then launch
So, we need to use another plugin here: Postbuildscript: Just put the shell script you've written yourself in. of course, you need some understanding of shell programming here .
For the realization of this deploy.sh, you can refer to this article: Http://www.linuxidc.com/Linux/2016-01/127258.htm

================ Split Line ===============================

First, install Jenkins

Address http://mirrors.jenkins-ci.org/Download the appropriate Jenkins version.

The Jenkins address for the latest stable version of Windows is: Http://mirrors.jenkins-ci.org/windows-stable/jenkins-1.409.1.zip

Https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service

The Jenkins 1.409.1 version of the decompression, the resulting war package is thrown directly under Tomcat, start Tomcat,jenkins installation is complete, is not very simple AH.

Second, configure Jenkins

1, open http://10.3.15.78:8080/jenkins/, the first time into the inside no data, we need to create a job, we have 2 projects, we need to create 2 jobs. http://10.3.34.163:9890/jenkins/

2, click on the new job in the upper left corner, the new job page needs to select the type of job, Jenkins supports several types, we choose "Build a MAVEN2/3 project", the job name is: guan_caijing,:

3, click the OK button, enter into the detailed configuration interface, detailed configuration of the interface a lot of configuration, but do not fear, most of the use of the default configuration can be, the following say we need to modify several places:

3.1) Source Code Management

Because we use SVN to manage the source code, here we choose Subversion and enter our SVN address in the repository URL:

http://10.3.34.163:9880/guan_caijing/trunk/

After entering the URL address of the SVN library, Jenkins automatically validates the address and gives hints.

Click the Enter credential link in the Red Font section to enter the following page:

After setting up a username and password to access the SVN library, click the OK button to display:

Description the setting was successful. Click the Close button to return to the previous source Code management page. There are no more red warning messages at this time.

3.2) Configure the automatic build plan, assuming that we want to build the project automatically once every day at 12 and 8 o'clock, just select build periodicallyin build triggersand schedule Enter 0 12,20 ** *.

I configured 8 per night. Point Auto-Build

Note: Schedule the configuration rules are 5 characters separated by spaces, representing from left to right: minutes when days Month years. * on behalf of all, 0 12,20 * * * means " 0 points" at any day of the year , any month, at any of the years .

3.3) Configure here, someone may find a red error message in the build configuration node, prompting

Jenkins needs to know where your Maven2 is installed.
The system configuration.

This is because Jenkins could not find the reason for MAVEN, click "System Configuration", the MAVEN configuration in the system configuration to add the directory is OK, such as:

I set up the installation directory for JRE 6 and Maven 3.

Click the Save button in the lower left corner to save your settings.

3.4) After all the configuration is saved, our 1th job is completed.

3.5) Create a 2nd job with the same configuration as above. Just change the SVN address to: Http://localhost/svn/Web

Third, manual construction

After the above configuration, go back to the Jenkins home page, you can see the 2 jobs just added, such as:

Click on a 1 job after the "Schedule a Build" image manually built, click Finish, will be on the left of the build queue or build Executor Status display the task being built, after the auto-build, refresh the page, you can see the build results, How to build a project fails, click on the build number behind the project (increment from 1) to enter the project's "Console Output" to see why the project failed to build. Of course we can also configure the results of the build failure to be sent to the mailbox.

So far, 1 simple auto-build environments have been set up, very simple.

Iv. Automatic Deployment

After reading the above found that the Jenkins configuration is really simple, a few minutes to build an automatic building environment, but the environment was set up to find 1 problems, now it can be automatically built, But the built-in Web.war are still in the Jenkins directory, not published in Tomcat, but also manually copy the past?

This is a problem, but don't worry, to achieve the purpose of automatic deployment, you need to install 1 Jenkins deployment plug-ins. Select Manage plugins on the System administration menu:

Select "Optional Plugin" to locate the deploy Plugin 1.8 plugin and select it.

Note: The Deploy Plugin 1.8 plugin supports Tomcat 4.x/5.x/6.x/7.x, JBoss 3.x/4.x, Glassfish 2.x/3.x

Click on the "Install" button at the bottom to display:

Wait patiently:

Until deploy plugin is complete, show success:

Select the box to tick and Jenkins will restart automatically:

At this point, on the Installed tab of the plug-in management, you can see that the deployment plug-in has been installed.

Re-enter the Web configure configuration interface, at the bottom of the discovery of more than 1 configuration items, we configured as follows:

Note: The war file uses a relative directory of Jenkinsworkspace, and the default directory for Hudon is:

C:\Documents and Settings\ user name \. Jenkins\

Workspace directory: C:\Documents and Settings\ user name \. Jenkins\ jobs\web\workspace\

The resulting war is in: C:\Documents and Settings\ user name \. Jenkins\ Jobs\web\workspace\web\target\web.war

Save the configuration and rebuild it again, open the Tomcat WebApps directory and discover that Web.war is finally here and done.

JENKINS+MAVEN+SVN quickly build a continuous integration environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.