As usual, the link is:
http://www.javaranch.com/journal/200409/DrivingOnCruiseControl_Part1.html
对于这个最著名的CI工具,我已经使用有一段时间了。但是因为有专门的build engineer所以偷懒到今天才来了解一下这个东西的基础知识。
- 什么是CI和CruiseControl?
要知道CruiseControl的用途,自然得先明白CI是什么。CI, continuous integration。
Technically, the term "Continuous Integration" means that everyone on the team integrates their changes back into the source repository frequently, verifying that the changes didn't break anything.
而集成+测试由完全自动化的工具完成,开发人员需要做的仅仅是将最新的改动提交至repository。CruiseControl就是这样一个自动化工具。
总的来说CI的目的就是实现 快速开发 + 保证质量。在agile越来越流行的今天,CruiseControl会流行就不足为奇了。
再来看官网上一段关于cruisecontrol的说明。有助于加深理解:
CruiseControl is both a continuous integration tool and an extensible framework for creating a custom continuous build process. It includes dozens of plugins for a variety of source controls, build technologies, and notifications schemes including email and instant messaging. A web interface provides details of the current and previous builds. And the standard CruiseControl distribution is augmented through a rich selection of 3rd Party Tools.
CruiseControl is written in Java but is used on a wide variety of projects. There are builders supplied for Ant, NAnt, Maven, Phing, Rake, and Xcode, and the catch-all exec builder that can be used with any command-line tool or script.
- How these Continuous Integration servers are typically set up in a project environment?
很简单。
1, Boxes of developer.
2, Box of repository.
3, CruiseControl server.
当开发人员将代码提交到repository时,CruiseControl就能检测到这种变化,build,execute最新的代码并运行UT,最后将结果以web,email等形式呈现给开发人员。另外build时使用的是Ant。其实就是build.xml脚本。
-
Setting Up the Repository and Working Copies
这里在repository server上build一个最最简单的repositiry by using Subversion.安装完Subversion后:
1. First, we need to create the repository itself:
C:/> svnadmin create c:/cia/repositoryserver/svnrepository 2. Second,创建一个Subversion自己要用的临时工作目录:
C:/> mkdir tmp/project C:/> cd tmp/project C:/tmp/project> mkdir branches C:/tmp/project> mkdir tags C:/tmp/project> mkdir trunk //这个trunk看着相当眼熟吧?
3. 把代码copy到trunk目录下。
4. import the directory structure into our repository:
svn import C:/tmp/project file:///c:/cia/repositoryserver/svnrepository -m "Initial import" 5.这时可以将tmp/project删除了。之后就可以在程序员的机器上checkout代码了。
-
Getting, Installing and Building CruiseControl
文章中有关于这几个folder的解释,非常重要。
main/bin --contains a batch/shell script for launching the CruiseControl process
main/logs --放置每个项目build结果的目录。每个项目会有自己的子目录。
main/dist --contains the cruisecontrol.jar
Reporting --contains the J2EE web application used for reporting CruiseControl build results online after each automated build.
-
Configuring CruiseControl
接下来的工作就是配置CruiseControl to tell it which projects it need to build and how.
配置文件是config.xml,下面是一个简介:
config.xml的完全参考是:http://cruisecontrol.sourceforge.net/main/configxml.html#project
<cruisecontrol> root element,可以有 project和plugin子节点。
<project> 多个项目是可以有多个project 节点。The <project> element is where you tell CruiseControl what to build, when to build, how to build, and how to report.
<project> element accepts two attributes. attribute name是project的名字。另一个可选的为buildafterfailed 表示build失败后是否继续build,即使没有新代码提交。
<property> The <property> element is used to set a property (or set of properties) within the CruiseControl configuration file. 一般可以用project.properties and specific.properties。
<bootstrappers> The <bootstrappers> element can be used to list bootstrappers, which are executed before the actual build attempt.
<modificationset> The <modificationset> element is where you specify how CruiseControl should figure out whether a build is needed。 这个貌似就是报表中显示的这次build涉及的代码的更改。
两个attributes:
requiremodification:如果没有代码改变,是否build
quietperiod:代码改动多长时间内不build,为了给程序员充分的提交代码的时间。
we can use the <svn> modificationset task to check whether any changes have been committed to the project associated with our working copy. Under the hood, the <svn> task performs a 'svn log' command to get a list of changes between the last build date and the start of the current build cycle.
注意这个node仅仅是说,在schedule的时间到了以后,参考该node来决定是否起一次build。而不是说,当发现related svn code改变后,就马上起一个build。
There's also a nice little task named <buildstatus> that you can use to trigger your build whenever another CruiseControlled project has had a successful build.
//这个很有用啊,比如build完这个project以后运行itf build。
<schedule> specifies how frequent you want your build cycle to start.
<schedule> takes just one attribute, interval, which represents a duration in seconds that CruiseControl will wait between build attempts.默认5分钟一次,也太短了吧!!
The children of <schedule> are called builders and are used for specifying the 'how' part of our configuration. The built-in builders provided out of the box, <ant> and <maven>, can be used to launch Ant and Maven build scripts, respectively. 这个也很重要!!
<schedule> 并不能单独决定什么时候启动一个build。需要和比如<project>和<modification>结合起来决定。
<log>
<publishers> 自然就是通知开发人员的方式了。可以有file,email,web pages and FTP
配置文件详解:
http://cruisecontrol.sourceforge.net/main/configxml.html
通常打开cc的工作目录可以看到以下文件。
-rw-r--r-- 1 16004 May 5 02:58 build.xml
-rw-r--r-- 1 6892 May 5 02:58 config.xml
-rw-r--r-- 1 47171 May 5 03:23 go.log
-rw-r--r-- 1 65 May 5 02:58 go.sh
-rw-r--r-- 1 1507 May 5 02:58 specific.properties
最后,launch CruiseControl!!
With the configuration file in place under "main/bin", you can finally launch CruiseControl with the following command:
C:/CruiseControl/main/bin> cruisecontrol
作者说要写的Part 2没有找到。。。
set up the reporting web application -- in Part 2...