Fork me on GitHub

持续集成 TeamCity 的配置与使用

环境:实现自动编译与自动化测试,发布到远程服务器,环境 VS2015 +WIN2008R2

什么是TeamCity

TeamCity是由Jetbrains开发的一款功能强大的持续集成(Continue Integration)工具,包括服务器端和客户端,目前支持Java,.Net 等项目开发。 TeamCity提供一系列特性可以让团队快速实现持续继承:IDE工具集成、各种消息通知、各种报表、项目管理、编译,单元测试,自动发布等等,所有的这些,都是让你的团队快速享有持续继承带来的效率提升、高质量的软件保障。TeamCity提供一个支持20个Build Configuration+3个Agent的免费版本。

配置WebDeploy

Visual Studio 默认提供三种发布的方式,文件,FTP,WebDeploy;最方便的还是WebDeploy,它可以在Visual Studio中一键部署到服务器上,并且智能判断哪些文件是新增的,哪些是需要修改或删除的。

下载: http://www.iis.net/downloads/microsoft/web-deploy [ 安装IIS选中管理工具 ]
1.启用Remote connections ,打开IIS中Management Service,勾选Enable Remote connections
2.IIS中选择项目启用webdeploy,生成配置文件
3.VS发布选择webdeploy选项,导入步骤2的配置文件
具体配置:
http://edi.wang/post/2013/12/21/iis-webdeploy-on-ws2008r2

配置TeamCity

win环境下安装比较简单,一路NEXT即可,配置过程中有可能会遇到如下问题:

选择数据库

The MS SQL Server JDBC driver is not found in the C:\ProgramData\JetBrains\TeamCity\lib\jdbc directory.
Download the driver from the Microsoft Download Center and follow the instructions and place the driver jar file into the C:\ProgramData\JetBrains\TeamCity\lib\jdbc directory on the server.

默认是没有MSSQL驱动的,需要复制jdbc驱动到C:\ProgramData\JetBrains\TeamCity\lib\jdbc目录[高版本的JDBC不可以]

Agent&MSBuildTools

Warning: No enabled compatible agents for this build configuration. Please register a build agent or tweak build configuration requirements.

默认Agent需要配置MSBuildTools14.0_x86_Path,需要安装MSBuildTools
http://stackoverflow.com/questions/20008861/team-city-unmet-requirement-msbuildtools12-0-x86-path-exists
Developer Tools Microsoft 生成工具 2015
https://www.microsoft.com/zh-CN/download/details.aspx?id=48159

创建项目

选择Create Project From URL重源码服务器上获取代码[git svn tfs等],Build Configurations 中我配置了两项

image

1.Build是编译源码

image

Triggers 配置每次有新的源码迁入时就编译一个版本

image

2.Deploy发布到测试服务器

/p:PublishProfile=WebDeploy.pubxml
/p:OutputPath=Release
/p:DeployOnBuild=True

/p:OutputPath=bin

image

Triggers 配置当第一步成功的时候触发

image

3.提交代码测试

此项目引用这台计算机上缺少的 NuGet 程序包。使用 NuGet 程序包还原可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 ..\packages\Microsoft.Net.Compilers.2.2.0\build\Microsoft.Net.Compilers.props。

启用nuget插件

image

默认会nuget获得第三方的包,可能因为nuget被墙的原因,需要多试几次下载有本地的环境就可以了

image

遇到的一些问题:

C:\TeamCity\buildAgent\work\177ef13051171b3c\xxx\xxx.Interface.csproj(361, 3): error MSB4019: 未找到导入的项目“C:\Program

Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets”。请确认 <Import> 声明中

的路径正确,且磁盘上存在该文件。C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio

解决方式:默认安装VS的机器拷贝C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio目录下的文件到安装TeamCity同样的目录下。

Controllers\HomeControllerTest.cs(2, 17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the

namespace 'Microsoft' (are you missing an assembly reference?)
Controllers\ValuesControllerTest.cs(7, 17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the

namespace 'Microsoft' (are you missing an assembly reference?)
Controllers\HomeControllerTest.cs(8, 6): error CS0246: The type or namespace name 'TestClass' could not be found (are you

missing a using directive or an assembly reference?)
Controllers\HomeControllerTest.cs(11, 10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you

missing a using directive or an assembly reference?)

解决方式:去除VS自带的测试DLL ,可以使用NUnit代替,相应的代码名称也得替换下:

[TestFixture] 
public class HomeControllerTest { 
    [Test]
    public void Index() 
    {
        // 排列 
        HomeController controller = new HomeController(); 
        // 操作 
        ViewResult result = controller.Index() as ViewResult; 
        // 断言 
        Assert.IsNotNull(result); Assert.AreEqual("Home Page", result.ViewBag.Title);
    }
}

 

 具体:http://www.cnblogs.com/ShineTan/archive/2012/03/26/2417475.html

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Deploy\Microsoft.Web.Publishing.MSDeploy.Common.targets(55,

5): 打包/发布任务 Microsoft.Web.Publishing.Tasks.CreateProviderList 未能加载 Web Deploy 程序集。此计算机上未正确安装

Microsoft Web Deploy。建议安装 Microsoft Web Deploy v3 或更高版本

解决方式:安装TeamCity的服务器安装WebDeploy

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4276, 5): error

ERROR_CERTIFICATE_VALIDATION_FAILED: Web 部署任务失败。 (已使用指定的进程(“Web Management Service”)连接到远程计算机

(“192.168.xxx.xxx”),但未能验证服务器的证书。如果你信任该服务器,请再次连接并允许不信任的证书。  在以下位置了解更多信息:

http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_CERTIFICATE_VALIDATION_FAILED 。)

解决方式:WebDeploy配置文件增加如下配置(https://msdn.microsoft.com/en-us/library/ff398069.aspx)

<!--信任证书-->
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4276, 5): error

ERROR_USER_UNAUTHORIZED: Web 部署任务失败。 (已使用 Web 管理服务连接到远程计算机(“192.168.xxx.xxx”),但未能授权。请确保你使

用了正确的用户名和密码、你连接的站点已存在并且凭据代表的用户有权访问该站点。  在以下位置了解更多信息:

http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED。)

解决方式:WebDeploy配置文件增加如下配置

<!--用户密码-->
<Password>xxxxxxxxxx</Password>

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets(195, 5): error MSB6003: The specified task executable "tsc.exe" could not be run. Could not find a part of the path 'C:\Program Files (x86)\Microsoft SDKs\TypeScript'

 解决方案:安装 TypeScript

升级版本:cope 安装包按照提示输入 log 下的 token 即可完成

 

REFER:

如何部署站点到指定的服务器上面

http://www.cnblogs.com/jiekzou/p/5257982.html
Nodejs开源项目里怎么样写测试、CI和代码测试覆盖率
https://cnodejs.org/topic/558df089ebf9c92d17e73358
用命令行脚本发布Azure网站
http://blchen.com/publish-azure-website-from-command-line-msbuild/
Jenkins搭建.NET自动编译测试与发布环境
http://blog.csdn.net/wangjia184/article/details/18365553
How to build ASP.NET applications in TeamCity with MSBuild Tools 2013 and .NET Framework 4.5 SDK
http://www.danmusk.com/how-to-build-asp-net-applications-in-teamcity-with-msbuild-tools-2013-and-net-framework-4-5-sdk/
Deploy ASP.NET projects from TeamCity with Web Deploy
http://www.danmusk.com/deploy-asp-net-projects-from-teamcity-with-web-deploy/
Continuous Integration & Delivery For GitHub With TeamCity
http://www.mehdi-khalili.com/continuous-integration-delivery-github-teamcity
How to: Edit Deployment Settings in Publish Profile (.pubxml) Files and the .wpp.targets File in Visual Studio Web Projects
https://msdn.microsoft.com/en-us/library/ff398069
Web Deployment Made Awesome: If You're Using XCopy, You're Doing It Wrong
https://channel9.msdn.com/Events/MIX/MIX10/FT14
Build ASP.NET 4.5 without Visual Studio on Build Server
http://stackoverflow.com/questions/12944502/build-asp-net-4-5-without-visual-studio-on-build-server
Team city unmet requirement: MSBuildTools12.0_x86_Path exists
http://stackoverflow.com/questions/20008861/team-city-unmet-requirement-msbuildtools12-0-x86-path-exists

https://nickcraver.com/blog/2016/05/03/stack-overflow-how-we-do-deployment-2016-edition/

https://octopus.com/

posted @ 2015-11-30 21:43  花儿笑弯了腰  阅读(9091)  评论(1编辑  收藏  举报