天天看點

Hudson:持續內建工具的安裝、使用

hudson簡介 

    以其強大的功能和易用的界面征服了大量的使用者,它與主流的建構工具、版本控制系統以及自動化測試架構都能進行很好的內建。 

    很多組織和公司選擇它作為自己的持續內建工具,如 

<a href="https://grid.sonatype.org/ci/">https://grid.sonatype.org/ci/</a>

    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 

<a href="http://hudson-ci.org/">http://hudson-ci.org/</a>

    安裝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 

    方式二:安裝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 &gt; /opt/maven/hudson_start.log 2&gt;&amp;1 &amp;

            檢視hudson程序 

            ps -ef|grep hudson.war 

        此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://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