Continuous integration CC

Source: Internet
Author: User

I have been paying close attention to CI tools for a while recently. I wrote this document just a little bit of time in the last two days. The latest version is 3.0, which can be downloaded from

  1. If you want to use it, you must download it first. The address will not be mentioned. I downloaded the latest If it is not a study, we suggest you download a bin package, which saves a lot of trouble. After decompression, we can see some directories.

    Among them, cruisecontrol (CC) comes with ant1.6.3. The document is under the docs Directory, which includes config. parameter settings in XML. Logs contains log information. specify the log path and name in the XML file. Under projects, continuous integration is required. jarkarta-Commons uses the math project of Apache as an example, and cruisecontrol is included in the lib directory. jar and other jar files required for running. webapps is the website of the cruisecontrol build result. You can view the build result by visiting http: // 8080/cruisecontrol; the artifacts directory is generated after the build, which is used to store the published artifacts.

  2. Preparations before using cruisecontrol
    1. Create source code for a CVS management project

      We recommend that you use CVS to manage the source code. You do not need to talk about the advantages here. For details about the creation process, refer to the relevant CVS user manual. here you need to pay attention to the Module Settings. You can refer to the relevant documentation to set them.

    2. Set ant Environment Variables

      The use of ant is not described in this article. Here we only talk about some possible situations. After configuring according to the ant user guide, you can try it in other environments. If your JDK is newer, you 'd better use the new Ant, here we use the built-in ant of CC. The environment in this article is jdk5.0 + ant1.6.3 + eclipse3.1 + tomcat5.5, OS: WINXP SP2

    3. Compile Project Build. xml

      Next we need to write the ant build. xml file. In this article, I have written such an example. To make it easy to understand, target uses Chinese. Next we will see it. In addition, when compiling the build file, I also found a problem. The Build File I wrote is not easy to use. If I run as ant, an exception will be reported, running ant at the command prompt does not solve this problem. After a period of checks, it is found that the ant version in eclipse is relatively low, after downloading the New Ant, the ant directory of eclipse is not updated. You need to perform the following settings:

    4. Checkout project to cc_home/Projects directory

      After cvsroot is configured, run $ CVS checkout module_name in cc_home/projects. This requires manual work; otherwise, CC will not automatically monitor changes.

    5. Modify config. xml

      Modify config. XML according to the actual project. An example is provided below.

  3. Run cruisecontrol

    After the above work, we can start CC.

    $ Cc_home/cruisecontrol. Sh; if you run cruisecontrol. bat on Windows, the following interface is displayed after the execution is successful:

    The prompt "project commons-Math started" and "buildqueue started" appears on the screen, indicating that CC has been correctly executed.

    After execution, we can view the build through IE. The interface is as follows:

    The following shows the build result. The current result is build failed. Because the network is disconnected when writing this document, you cannot connect to Apache to obtain the program for compilation, and an error occurs.

    We can see that CC also provides the RSS subscription function. With the help of RSS reader, we can easily obtain the latest construction information. The interface is as follows:

    Well, we have seen the process of using CC. Let's use an example to implement this process.

  4. Example

    In this example, we create a new project named hello. The project structure is as follows:

      Main/src/Java/COM/test/Qik/hellomaven. Java: Sample program

    Package com. Test. Qik; public class hellomaven {public static Boolean main (string [] ARGs) {system. Out. println ("Hello, Maven! "); Return true;} public void TESTA () throws exception {system. out. println ("test, which can be released to the production database version");} Main/test/Java/COM/test/Qik/hellomaventest. java: unit test case package COM. test. qik; import JUnit. framework. testcase; public class hellomaventest extends testcase {public static void main (string [] ARGs) {} public hellomaventest (string arg0) {super (arg0);} protected void setup () throws exception {super. setup ();} PR Otected void teardown () throws exception {super. teardown ();}/** Test Method for 'com. test. qik. hellomaven. main (string []) '*/Public void testmain () {hellomaven Hm = new hellomaven (); assertequals (HM. main (null), true) ;}} target/: Output path build. XML: the content of the ant build file is as follows: ========================================================== ======================================<? XML version = "1.0" encoding = "UTF-8"?> <Project default = "Ci" name = "hello" basedir = "."> <! -- Set parameters --> <property name = "project Chinese name" value = "test CC project"> </property> <property name = "project_folde" value = "E: /cruisecontrol-2.3.1/projects/Hello "> </property> <property name =" source program directory "value =" $ {project_folder}/main/src "> </property> <property name = "test program directory" value = "$ {project_folder}/main/test"> </property> <property name = "compile program directory" value = "$ {project_folder }/ target/classes "> </property> <property name =" lib directory "value =" $ {projec T_folder}/target/lib "> </property> <property name =" unit test report directory "value =" E: /cruisecontrol-2.3.1/projects/Hello/test-Reports "> </property> <property name =" unit test report file name "value =" junit-noframes.html "> </property> <property name = "CVS username" value = "Administrator"> </property> <property name = "CVS password" value = "patterns"> </property> <property name = "CVS address" value = ""> </property> <property name = "cvs repository" value = "/cvsserver"> </PR Operty> <property name = "CVS module" value = "hello"> </property> <property name = "cvslib module" value = "target"> </property> <Property name = "CVS connector" value = ": pserver :$ {CVS username }:: {CVS password }@$ {CVS address}: 2401: $ {cvs repository} "> </property> <property name =" CVS check-out directory "value =" E: /cruisecontrol-2.3.1/Projects "> </property> <property name =" "" value = ""> </property> <property name = "" value = "XXX"> </property> <property name = "Send Email Password "value =" xxxxxx "> </property> <! -Enter the plaintext user name and password, in the example, do not enter --> <property name = "Accept report user email list" value = ""> </property> <property name = "Send user email address" value =" "> </property> <property name =" generate JAR file "value =" E: /cruisecontrol-2.3.1/projects/Hello/target/hello. jar "> </property> <property name =" basic path for generating jar Files "value =" E: /cruisecontrol-2.3.1/projects/Hello/target/classes "> </property> <! -- Continuous integration process --> <target name = "Ci" depends = "initialize, obtain the source code, compile the source code, run the test, and generate the jar"/> <! -- 1. initialize the target directory, clear the target directory, create the source directory, test the program directory and class directory --> <target name = "initialization"> <echo> deleting the source directory... </echo> <Delete dir = "$ {source program directory}"/> <echo> creating source program directory... </echo> <mkdir dir = "$ {source program directory}"/> <echo> deleting the test program directory... </echo> <Delete dir = "$ {test program directory}"/> <echo> creating a test program directory... </echo> <mkdir dir = "$ {test program directory}"/> <echo> deleting the Compiling Program directory... </echo> <Delete dir = "$ {Compiling Program directory}"/> <echo> creating Compiling Program directory... </echo> <mkdir dir = "$ {Compiling Program directory}"/> <echo> deleting lib directory... </echo> <delet E dir = "$ {lib directory}"/> <echo> creating lib directory... </echo> <mkdir dir = "$ {lib directory}"/> <echo> deleting the unit test report directory... </echo> <Delete dir = "$ {unit test report directory}"/> <echo> creating a unit test report directory... </echo> <mkdir dir = "$ {unit test report directory}"/> </Target> <! -- 2. obtain the program source code from CVS --> <target name = "Get source code" depends = ""> <echo> obtain the source code from CVS... </echo> <CVS cvsroot = "$ {CVS connector}" command = "Export-F-r head $ {CVS module}" DEST = "$ {CVS check-out directory }" /> </Target> <target name = "Get lib"> <echo> obtain the lib directory from CVS... </echo> <CVS cvsroot = "$ {CVS connector}" command = "Export-F-r head $ {cvslib module}" DEST = "$ {CVS check-out directory }" /> </Target> <! -- 3. compile the program to generate the target class --> <target name = "compile source code" depends = ""> <echo> compile the program... </echo> <javac classpathref = "Compiling path" fork = "true" memorymaximumsize = "128 M" destdir = "$ {Compiling Program directory}" DEBUG = "true" deprecation = "false" failonerror = "false" verbose = "false"> <SRC Path = "$ {source program directory}"/> <SRC Path = "$ {test program directory }"/> <include name = "**/*. java "/> </javac> </Target> <! -- 4. run JUnit test --> <target name = "Run test" depends = "" Description = "Run unit test"> <echo> RUN unit test cases... </echo> <JUnit> <classpath refID = "unit test path"/> <formatter type = "XML"/> <batchtest todir = "$ {unit test report directory} "> <fileset dir =" $ {compiled program directory} "> <exclude name =" **/testtools. class "/> <include name =" **/** test **. class "/> </fileset> </batchtest> </JUnit> <echo> Generate the unit test report... </echo> <junitreport todir = "$ {unit test report directory}" Description = "generate unit test report"> <fileset Dir = "$ {unit test report directory}"> <include name = "test -*. XML "/> </fileset> <report format =" noframes "todir =" $ {unit test report directory} "/> </junitreport> </Target> <! -- 5. email --> <target name = "Send test report email" depends = ""> <echo> send test report email... </echo> <mail mailhost = "$ {email server address}" subject = "unit test report: $ {Chinese project name}-$ {dstamp} "user =" $ {email sending user} "Password =" $ {email sending password} "tolist =" $ {report receiving user email list} "messagefile =" $ {unit test report directory}/$ {unit test report file name} "> <FROM address =" $ {sending user email address} "/> <fileset file = "$ {unit test report directory}/$ {unit test report file name}"/> </mail> </Target> <! -- 6. package it into a jar file --> <target name = "generate jar" depends = ""> <echo> package it into a jar file... </echo> <jar destfile = "$ {generate JAR file}" basedir = "$ {basic path to generate JAR file}"/> </Target> <! -- Path used during compilation --> <path id = "Compilation path"> <pathelement Path = "$ {Compiling Program directory}"/> <path refID = "lib during compilation path "/> </path> <path id =" lib path during compilation "> <fileset dir =" $ {lib directory} "> <include name = "**/*. jar "/> </fileset> </path> <! -- Path used in unit test --> <path id = "path for unit test"> <path refID = "lib path for compilation"/> <pathelement Path = "$ {compile program directory} "/> </path> </Project> ======================== ==========================================. content set in XML <cruisecontrol> <project name = "hello"> <listeners> <currentbuildstatuslistener file = "logs/Hello/status.txt"/> </listeners> <bootstrappers> <cvsbootstrapper localworkingcopy = "projects/Hello"/> </bootstrappers> <! -Monitor the local working directory. If the directory below changes, the following build is automatically executed. XML. if no changes are made, the following build tasks will not be executed --> <modificationset quietperiod = "30"> <! -Silent before monitoring --> <CVS localworkingcopy = "projects/Hello"/> <CVS localworkingcopy = "projects/Hello/main/src/Java/COM/test/Qik "/> </modificationset> <! -Scheduled time interval, in seconds --> <schedule interval = "30"> <ant anthome = "Apache-ant-1.6.3" buildfile = "projects/Hello/build. XML "target =" Ci "/> <! -Build. xml --> </schedule> <log> <merge dir = "projects/Hello/test-Reports"/> </log> <! -Record the location of the log report --> <publishers> <artifactspublisher DEST = "artifacts" file = "projects/Hello/target/Hello. Jar"/> </publishers> <! -The location where the jar package is released. in XML, lay the jar package in this location --> </Project> </cruisecontrol> cc_home/docs/main/configxml.html. The file is config. XML help content, we can find all the configurations from here.
  5. Summary

    We can see that the entire process is still very simple. Through CC, We can partially reduce the CI workload, but we can see that the core build work is still in the project build. in XML, it would be better if CC could provide common templates (Haha, I still want to be lazy ). In addition, the function of monitoring the local working directory of CC is somewhat retarded. For example, I only wrote "projects/Hello ", it only considers that the build process is started when the files in the "Project/Hello" directory are updated. If we update the following sub-directories, it cannot be automatically monitored.

Related Article

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: 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.