持续集成(CI)- TeamCity实战概览

持续集成(CI)- TeamCity实战概览,第1张

概述之所以选择TeamCity,有以下几个原因: Ø 这个软件对于小团队可以免费使用 Ø 安装配置比较简单,系统的要求不是很高(相比VS 2010 TFS) Ø 使用和配置比Cc.net简单一些 Ø 包含了重复代码的检测和分析工具 一、SVN安装 SVN服务安装 http://www.visualsvn.com/files/VisualSVN-Server-2.1.7.msi SVN客户端 Torto

之所以选择TeamCity,有以下几个原因:

Ø 这个软件对于小团队可以免费使用

Ø 安装配置比较简单,系统的要求不是很高(相比VS 2010 TFS)

Ø 使用和配置比Cc.net简单一些

Ø 包含了重复代码的检测和分析工具

一、SVN安装

SVN服务安装 http://www.visualsvn.com/files/VisualSVN-Server-2.1.7.msi

SVN客户端

TortoiseSVN

VisualSVN-2.0.5.msi

二、TeamCity安装

http://www.jetbrains.com/teamcity/ 下载 TeamCity-6.0.3.exe

三、TeamCity实战

如下把涉及到的多个方面简要汇总一下,具体的内容可以试用一下,或者从参考中下载图书的代码内容分析。一般的项目也不会全部涉及,根据项目的情况和内容裁减即可。

1、建立CI项目

默认的ci管理网址在 http://localhost/

按照提示建立项目即可

成功后即可建立各种类型的Build

2、NUnit、覆盖率测试

TeamCity comes with built-in functionality for NCover and PartCover. To use PartCover,you have to set it up on the Build Configuration page.

First,enable NUnit Tests (mark the flag in New Unit Test Settings). Set it to run the tests from

%system.teamcity.build.workingDir%\CIDotNet.Calc.Test\bin\Release\CIDotNet.Calc.Test.dll.

Go to the .NET Coverage section,choose PartCover from the drop-down List,and provIDe the path to the executables in the lib directory

(%system.teamcity.build.workingDir%\lib\PartCover\PartCover.exe).

Report XSLT:

C:\Program files (x86)\PartCover\PartCover .NET 4.0\xslt\Report By Assembly.xslt=> PartCover.Assembly.HTML

C:\Program files (x86)\PartCover\PartCover .NET 4.0\xslt\ Report By Class.xslt=> PartCover.Class.HTML

PartCover在64位下执行的方法

CorFlags.exe PartCover.exe /32BIT+ /Force

3、MSTest测试MSBuild形式

<Project DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>

<!--Default Configuration-->

<Configuration Condition=" '$(Configuration)' == '' ">DeBUG</Configuration>

<!--Default Platform-->

<Platform Condition=" '$(Platform)' == '' ">"Any cpu"</Platform>

<!--Visual Studio path-->

<VSPath Condition=" '$(VSPath)' == '' ">%Programfiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE</VSPath>

<!--AsseblIEs to test-->

<TestAssemblIEs>CIDotNet.Calc.Test\bin$(Configuration)\CIDotNet.Calc.Test.dll</TestAssemblIEs>

</PropertyGroup>

<Target name="Build" >

<MSBuild Targets="Clean;Rebuild" Projects="CIDotNet.sln" ContinueOnError="false"/>

</Target>

<Target name="Test" DependsOnTargets="Build">

<Delete Condition="Exists('MSTestReport.trx')" files="MSTestReport.trx"></Delete>

<Exec Command="&quot;$(VSPath)\MSTest.exe&quot; /testcontainer:$(TestAssemblIEs) /resultsfile:MSTestReport.trx"/>

<Message Text="##teamcity[importData type='mstest' path='MSTestReport.trx']" ></Message>

</Target>

</Project>

4、MSTest

MSTest.exe 命令行选项

http://msdn.microsoft.com/zh-cn/library/ms182489.aspx

· Build Log

[16:26:40]: 测试设置: 本地

[16:26:42]: ##teamcity[importData ID='mstest' file='D:\pm\TeamCity\buildAgent\work\eea58b62b6f4c74d\MSTestReportX.trx']

[16:26:42]: importing data from 'D:\pm\TeamCity\buildAgent\work\eea58b62b6f4c74d\MSTestReportX.trx' with 'mstest' processor

[16:26:42]: MSTest

[16:26:42]: [MSTest] Found 1 test deFinitions.

[16:26:42]: [MSTest

找到MSTestReportX.trx文件,VS打开即可看到覆盖率

5、Integration tests

不像单元测试,尽量减少组件之间的关联,依赖的组件使用Mock框架进行模拟

此时引入相关的依赖组件,替换掉Mock

6、其他测试

参考中图书第7章的例子代码拿来用用

涉及:

White框架

CIDotNet.Wincalc.Test: WinForm的测试

CIDotNet.SilverlightCalc.Test: Silverlight的测试

Selenium框架 http://seleniumhq.org/

CIDotNet.WebCalc.Test

8、代码规范

这部分主要是修改项目文件,支持Build,然后提供信息反馈处,具体的设置参考如下

Fxcop

使用Fxcop的项目进行集成,*.fxcop 是项目文件

<Target name="Analyze">

<Delete Condition="Exists('FxcopReport.xml')" files="FxcopReport.xml"></Delete>

<fileUpdate files="CIDotNet.Fxcop" Regex="bin/DeBUG" ReplacementText="bin/$(Configuration)" />

<Exec Command="tools\Fxcop\FxcopCmd.exe /project:CIDotNet.Fxcop /out:FxcopReport.HTML /axsl"/>

<Error Condition="Exists('FxcopReport.xml')" Text="Fxcop found some broken rules!" />

define a new artifact FxcopReport.HTML and a new tab server configuration.

Stylecop

<Project DefaultTargets="Analyze" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<UsingTask Assemblyfile="tools\msbuildcommunitytasks\MSBuild.Community.Tasks.dll" Taskname="MSBuild.Community.Tasks.fileUpdate"></UsingTask>

<UsingTask Assemblyfile="tools\msbuildcommunitytasks\MSBuild.Community.Tasks.dll" Taskname="MSBuild.Community.Tasks.Xslt"></UsingTask>

<UsingTask Assemblyfile="tools\msbuildcommunitytasks\MSBuild.Community.Tasks.dll" Taskname="MSBuild.Community.Tasks.XmlRead"></UsingTask>

<UsingTask Assemblyfile="tools\Stylecop\Microsoft.Stylecop.dll" Taskname="StylecopTask"/>

<CreateItem Include="CIDotNet.Calc\**\*.cs">

<Output TaskParameter="Include" Itemname="Stylecopfiles"/>

</CreateItem>

<StylecopTask

ProjectFullPath="$(MSBuildProjectfile)"

Sourcefiles="@(Stylecopfiles)"

ForceFullAnalysis="true"

TreatErrorsAsWarnings="true"

Outputfile="StylecopReport.xml"

CacheResults="true"

AdditionalAddinPaths="tools\"

/>

<Xslt inputs="StylecopReport.xml"

Roottag="StylecopViolations"

Xsl="tools\Stylecop\StylecopReport.xsl"

Output="StylecopReport.HTML" />

<XmlRead XPath="count(//Violation)"

Xmlfilename="StylecopReport.xml">

<Output TaskParameter="Value" Propertyname="StylecopViolations" />

</XmlRead>

<Error Condition="$(StylecopViolations) > 0" Text="Stylecop found some broken rules!" />

add the artifact file,and a new tab appears in the build report page

代码重复

Its purpose is to find the places in your code where your team has duplicated the code.

The Duplicates Finder is a separate build runner in TeamCity.

9、文档

基于Sandcastle 的形式

<Target name="document" >

<MSBuild Projects="CIDotNet.shfbproj"/>

</Target>

TeamCity project’s General Settings,and set the Artifacts path to

Help/**/* => Help

This causes all the Help folder content from the current build to be copIEd to the Help artifacts folder. To make the documentation visible on the build-report page,add a new tab in the server configuration,pointing to /Help/Index.HTML.

10、安装和部署

WIX安装

ClickOnce部署

MS Deploy部署

<Target name="Setup" >

<Exec

Command="&quot;$(VSPath)\devenv.exe&quot; CIDotNet.sln /build &quot;$(Configuration)&quot; /project CIDotNet.Wincalc.Setup\CIDotNet.Wincalc.Setup.vdproj"

ContinueOnError="false" IgnoreExitCode="true"

/>

<MSBuild Projects="CIDotNet.Wincalc.Wix\CIDotNet.Wincalc.Wix.wixproj" PropertIEs="WixTargetsPath=$(MSBuildProjectDirectory)\tools\Wix\Wix2010.targets;"/>

</Target>

<Target name="Publish" >

<MSBuild Targets="Publish" Projects="CIDotNet.sln" ContinueOnError="false" PropertIEs="ApplicationVersion=$(Major).$(Minor).$(Build).$(Revision)"/>

</Target>

<Target name="WebPublish" >

<MSBuild Targets="Package" Projects="CIDotNet.WebCalc\CIDotNet.WebCalc.csproj" ContinueOnError="false" PropertIEs="PackageLocation=WebPublication\Package.zip;MSBuildExtensionsPath32=..\tools"/>

<Exec

Command="CIDotNet.WebCalc\WebPublication\Package.deploy.cmd /Y /m:ci1 /u:administrator /p:marcinq1p0w2"

ContinueOnError="false" IgnoreExitCode="true"

/>

</Target>

11、数据库集成

这个主要使用VS的数据库项目可以完成

<MSBuild

Projects = "$(SolutionRoot)\NWSandBox.dbproj"

PropertIEs = "Configuration=DeBUG; TargetDatabase=NewDBname"

Targets = "Deploy"/>

四、参考

图书Continuous Integration in .NET http://www.manning.com/kawalerowicz/ 下载CIi.N_SourceCode.zip

其中包括VS的Build脚本等,在TFS的持续集成中可以参考

http://www.cnblogs.com/2018/category/300477.html

总结

以上是内存溢出为你收集整理的持续集成(CI)- TeamCity实战概览全部内容,希望文章能够帮你解决持续集成(CI)- TeamCity实战概览所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1068687.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存