zoukankan      html  css  js  c++  java
  • 持续集成:CruiseControl.NET + VisualSVN.Server

    持续集成:CruiseControl.NET + VisualSVN.Server

    刚换了工作,有需要搭建一套持续集成的平台,做一下总结。

      首先是我用到的工具:

                  

      上面缺少了Microsoft Fxcop,可以用来做代码校验,不过实际情况暂时还没有用到。主要的需求目前是,使用已发布的稳定版本代码作为新发布版本代码的基础,避免有未完成的代码存在于发布版本中,同时自动化集成发布后,上传该新发布版本代码到tags中。elevate一般情况下是不需要的,不过VisualSVN无法使用命令行登陆,可以使用它来提升执行权限,不过最终我使用了另外一个办法,这个方法需要购买VisualSVN Server的License,后面会说。

      安装过程就不赘述了,相信有兴趣看这个的都是做软件的,下一步之类还有一些选项什么的没什么可说的。安装的时候部署的监控网站可能不成功,只要自己手动在IIS上布下就好。另外,先提一句CCTray是可以把配置好的集成方案服务添加运行的工具,添加好后本身也具有监控的功能,区别是它客户端工具。

      先说SVN服务器,VisualSVN Server是比较简单的SVN服务端,所以功能比较简单,比如就缺少命令行登陆的功能,不过另一方面就是安装很简单。有两点需要说明一下,一是新建Repository时,勾选分为branches tags trunk三个目录,分别用来放分支代码,发布版代码,主干版本代码,其中tags下的代码是只能新增不能修改的;另外一点是权限问题,我使用的是windows的账户做操作的,在这种情况下,有个选项要勾选上,不然执行svn提交代码命令时,会报错身份验证不通过。

                          

      上图红框就是需要勾选的,不过勾选这个是需要License的。

      接下来就是主题部分了,安装完CC以后,到开始菜单里找到对应的菜单,会发现里面有个配置文件,对应的就是安装好的目录下的ccnet.config文件,另外还有个验证工具,可以用来辅助配置,一目了然的东西就不细说了,下面说说配置。

    复制代码
    <cruisecontrol xmlns:cb="urn:ccnet.config.builder">
      <!-- This is your CruiseControl.NET Server Configuration file. 
           Add your projects below! -->
    
    这里配置服务的名字,一个project对应的就是一个集成方案,可以独立执行 <project name="ProjectTest" description="demoproject showing a small config" queue="Q1">
    工作使用的目录 <workingDirectory>D:Store</workingDirectory>
    这里是正在集成工程中的临时配置文件保存的地方,一次执行结束后,该配置文件会被放到配置的日志文件夹中
       <artifactDirectory>D:StoreArtifacts</artifactDirectory> <!-- specify a state folder to prevent CCNet from saving it in Program FilesCruiseControl.NETserver programs may not standard write their data in it on windows Vista and up) --> <state type="state" directory="D:StoreState" /> <!-- specify a artifactDirectory to prevent CCNet from saving it in Program FilesCruiseControl.NETserver programs may not standard write their data in it on windows Vista and up) --> 这是监控页面
    <webURL>http://localhost:90/ViewLatestBuildReport.aspx</webURL> <modificationDelaySeconds>10</modificationDelaySeconds> <triggers> <!-- check the source control every X time for changes, and run the tasks if changes are found --> <!--<intervalTrigger name="continuous" seconds="30" buildCondition="IfModificationExists" initialSeconds="5"/>--> <intervalTrigger name="continuous" seconds="6000" /> </triggers>
    这里是配置获取源码的位置,使用svn <sourcecontrol type="svn"> <executable>C:Program FilesVisualSVN Serverinsvn.exe</executable> <trunkUrl>https://aaa/svn/Test/trunk</trunkUrl> <username>svn</username>--登陆svn使用的用户名密码,这个是我在测试服务器上创建的测试账户 <password>svn</password> <workingDirectory>D:StoreCode</workingDirectory>--获取下来源码的存放位置 <autoGetSource>true</autoGetSource> </sourcecontrol> <tasks> <!-- if you want the task to fail, ping an unknown server -->
    这个ping的作用在这里仅仅是测试的时候,改成错的可以让它后面的配置都不执行 <exec> <executable>ping.exe</executable> <buildArgs>localhost</buildArgs> <buildTimeoutSeconds>15</buildTimeoutSeconds> <description>Pinging a server</description> </exec> 这里是编译解决方案的配置,也可以每个项目分别编译,projectFile配置成项目的csproj文件就可以
          <msbuild>
            <executable>C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe</executable>
            <workingDirectory>D:StoreCode</workingDirectory>
            <projectFile>D:StoreCode*******.sln</projectFile>
            <buildArgs>/noconsolelogger /p:Configuration=Release;OutDir=D:StoreRun /v:diag</buildArgs>
            <logger>C:Program FilesCruiseControl.NETserverThoughtWorks.CruiseControl.MSBuild.dll</logger>
            <targets>Build</targets>
            <timeout>900</timeout>
          </msbuild>
    
    这是用来配置发布位置的,sourceDir是生成的位置,publishDir是发布的位置可以配置成远程的共享目录
    <buildpublisher> <sourceDir>D:StoreRun</sourceDir> <publishDir>D:StoreRelease</publishDir> <useLabelSubDirectory>false</useLabelSubDirectory> </buildpublisher> <!--删除.svn文件--> 这个批处理文件时用来清除代码中svn绑定的,因为这份代码需要提交到Tags上,这个批处理代码类似的网上到处都是我就不贴了
    <exec executable="D:StoredelSVN.bat" />
    这段注释掉的是单元测试的配置,不过由于原来的代码都没做单元测试,所以就先注释掉了 <!--删除单元测试结果文件,否则不会创建新的结果文件 <exec executable="D:StoredelTestResult.bat" />--> <!-- buildArgs:参数,/testcontainer:单元测试项目程序集(可以包含多个) /resultsfile:测试结果文件 <exec> <executable>C:Program FilesMicrosoft Visual Studio 11.0Common7IDEmstest.exe</executable> <baseDirectory>D:StoreUNTest</baseDirectory> <buildArgs>/testcontainer:TestProjectinDebugTestProject.dll /resultsfile:TestResultsmstest-results.xml</buildArgs> <buildTimeoutSeconds>300</buildTimeoutSeconds> </exec>--> 提交代码的批处理:

    cd /d %~dp0
    "C:Program FilesVisualSVN Serverinsvn.exe" import -m "New Tags" D:StoreCode https://aaa/svn/Test/tags/Tags_%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

          <!--提交Tags代码-->
          <exec executable="D:StoresvnCTags.bat" />
        </tasks>
    
        <publishers>
    这个是完成后全部的日志
    <xmllogger logDir="D:StoreLog"/> 日志可以配置成发送邮件,不过这里不需要 </publishers> </project> 第二个集成服务
    <project name="ProjectTestWithOutGetSource" description="demoproject showing a small config" queue="Q1"> <workingDirectory>D:Store</workingDirectory> <artifactDirectory>D:StoreArtifacts</artifactDirectory> <state type="state" directory="D:StoreState" /> <webURL>http://localhost:90/ViewLatestBuildReport.aspx</webURL> <modificationDelaySeconds>10</modificationDelaySeconds> <triggers> <intervalTrigger name="continuous" seconds="6000" /> </triggers> <sourcecontrol type="svn"> <executable>C:Program FilesVisualSVN Serverinsvn.exe</executable> <trunkUrl>https://aaa/svn/Test/trunk</trunkUrl> <username>svn</username> <password>svn</password> <workingDirectory>D:StoreCode</workingDirectory> <autoGetSource>true</autoGetSource> </sourcecontrol> <tasks> <!-- if you want the task to fail, ping an unknown server --> <exec> <executable>ping.exe</executable> <buildArgs>localhost</buildArgs> <buildTimeoutSeconds>15</buildTimeoutSeconds> <description>Pinging a server</description> </exec> <msbuild> <executable>C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe</executable> <workingDirectory>D:StoreCode</workingDirectory> <projectFile>D:StoreCode*******.sln</projectFile> <buildArgs>/noconsolelogger /p:Configuration=Release;OutDir=D:StoreRun /v:diag</buildArgs> <logger>C:Program FilesCruiseControl.NETserverThoughtWorks.CruiseControl.MSBuild.dll</logger> <targets>Build</targets> <timeout>900</timeout> </msbuild> <buildpublisher> <sourceDir>D:StoreRun</sourceDir> <publishDir>D:StoreRelease</publishDir> <useLabelSubDirectory>false</useLabelSubDirectory> </buildpublisher> <!--删除.svn文件--> <exec executable="D:StoredelSVN.bat" /> <!--提交Tags代码--> <exec executable="D:StoresvnCTags.bat" /> </tasks> <publishers> <xmllogger logDir="D:StoreLog"/> </publishers> </project> </cruisecontrol>
    复制代码

    最后是我集成使用的测试目录,可以不用自己创建,集成过程中会自己创建的

                        

     
    分类: 候选实现
    标签: CI
  • 相关阅读:
    我的Java学习推荐书目
    BTrace使用简介
    BTrace使用小结
    如何在生产环境使用Btrace进行调试
    BTrace : Java 线上问题排查神器
    淘宝Tprofiler工具实现分析
    JVM 性能调优实战之:使用阿里开源工具 TProfiler 在海量业务代码中精确定位性能代码
    性能工具TProfiler介绍文档
    分布式系统理论基础
    微信小程序
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/4003621.html
Copyright © 2011-2022 走看看