Hudson:持续集成工具的安装、使用

原创
2013/11/26 14:37
阅读数 2.1K

Hudson简介
http://hudson-ci.org
    以其强大的功能和易用的界面征服了大量的用户,它与主流的构建工具、版本控制系统以及自动化测试框架都能进行很好的集成。
    很多组织和公司选择它作为自己的持续集成工具,如
http://hudson.jboss.org/hudson
https://grid.sonatype.org/ci/

    Hudson还有一个优秀之处就是它提供了灵活的插件扩展框架,大量开发者基于这种机制对Hudson进行了扩展。

安装Hudson
    注意:Hudson必须运行在JRE1.6或更高的版本上,安装时需要联网
    Hudson only needs a Java 6 or newer runtime. An internet connection will be required if you want to be able to install and auto-update plug-ins
http://hudson-ci.org/

    安装Hudson有两种方式:
    方式一:直接运行war(This is mostly useful for testing purposes)
        1:下载hudson-3.0.0.war
        2:启动Hudson的方式是在命令行直接运行hudson.war
            $cd /opt/maven
            $java -jar hudson-3.0.0.war
            $java -jar hudson-3.0.0.war --httpPort=8082
        3:启动完成之后,在浏览器地址栏输入:http://localhost:8082/访问Hudson界面
    方式二:安装rpm(For production we recommend using native packages for simplified install )
        1:下载hudson-3.0.0-1.1.noarch.rpm
        2:安装rpm
        3:执行如下命令(需要root用户操作)
            cd /opt/maven
            rpm -ivh hudson-3.0.0-1.1.noarch.rpm
            /etc/init.d/hudson start

            nohup /etc/init.d/hudson start > /opt/maven/hudson_start.log 2>&1 &

            查看hudson进程
            ps -ef|grep hudson.war
        4:启动完成之后,在浏览器地址栏输入:http://localhost:8080/访问Hudson界面
        此rpm包做了如下工作:
            Hudson will be launched as a daemon up on start. See /etc/init.d/hudson for more details.
            The hudson user is created to run this service.
            Log file will be placed in /var/log/hudson/hudson.log. Check this file if you are troubleshooting Hudson.

    因为Hudson was written to work on unix-like platforms,所以不建议在windows上面安装,如果安装,则需要先UnxUtils
    具体参见:http://wiki.eclipse.org/Hudson-ci/Installing_Hudson

    打开http://172.168.27.70:8080/页面后,根据需要安装插件,如果选择的很多,将需要很久的时间
    如果全部安装后,点击finished

    hudson系统配置
    进行系统管理--系统配置,配置JDK
    JDK安装:
    JDK-1.6  /usr/java/jdk1.6.0_33

    全局MAVEN_OPTS
    -Xms128M
    -Xmx512M

    如果打开系统配置报:
    Problem accessing /checkURIEncoding. Reason:  Tried to read incomplete UTF8 decoded String

    此问题在IE下存在,而在firefox下面不存在,请使用firefox浏览器

 

创建Hudson任务
    任务类型选择:构建一个自由风格的软件项目(Build a free-style software project)
        不仅支持Maven项目,还支持其他类型的构建工具,如Ant、Shell
        而对于Maven用户来说,两者最大的不同在于前者需要用户进行多一点配置,而后者会使用Hudson自带的Maven,且从项目的POM中获取足够的信息以免
        去一些配置。
        推荐使用free-style类型,这种方式更可控制,当任务出现问题的时候也更容易检查。
        1:首先是项目的名称和描述
        2:Discard Old Builds.该选项配置如何抛弃旧的构建。因为Hudson每执行一次构建任务,就可以保存相应的源代码、构建输出、构建报告等文件。
            Days to keep builds
            Max # of builds to keep
        3:项目使用的JDK配置,这里可以选择的JDK就是用户在系统设置中预定义好的JDK(当前仅仅配置了一个,不用配置)
        以上三项为基本配置

        Hudson任务的源码仓库配置
        4:Source Code Management
            选择Subversion
            svn://172.168.9.101/account/trunk

            一般来说,该部分的其他选项保留默认值即可。
        Hudson任务的构建触发配置
        5:Build Triggers
            选择poll SCM    周期性地轮询源码仓库,发现有更新的时候构建本项目,是最常用的构建触发方式
            使用了Cron任务调度工具进行配置,如10分钟轮询一次
            */10 * * * *

        6:Hudson任务的构建配置 Build
            告诉Hudson使用运行Maven命令构建项目。从Add build step选择Maven3
            选择Maven Version(选择bundle) 和 Goals如clean install

            clean install -Dmaven.test.failure.ignore
            此参数配置构建命令忽略测试。这样失败的测试就不会导致构建失败。即不稳定的构建,任务状态为黄色。

        针对account项目,需要停断邮件服务(占用了25端口,而greenmail测试邮件绑定此端口)
        ervice sendmail stop
        chkconfig sendmail off

        任务执行时
        hudson在
        /var/lib/hudson/jobs/
        根据任务的名称构建项目
        hudson绑定的Maven仓库地址是:
        /var/lib/hudson/.m2/repository

        使用的用户是hudson:hudson

        配置Maven项目测试报告:
        Post-build Actions
        选择Publish JUnit test result report
        Test report XMLs中输入:**/target/surefire-reports/TEST-*.xml

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
3 收藏
0
分享
返回顶部
顶部