之前寫過一篇文章是在CentOS上構建.net自動化編譯環境, 今天這篇是針對於Windows平台的環境。
Jenkins是一個開源軟件項目,旨在提供一個開放易用的軟件平台,使軟件的持續集成變成可能。Jenkins是基於Java開發的一種持續集成工具,用於監控持續重復的工作,
Jenkins是由Sun的前員工開發的,它的根基是Java,但也可以用在非Java的項目里,比如PHP、Ruby on Rails、.NET。持續集成相關的工具有很多。它提供了Web界面,用戶可以在界面
上配置Job,每個Job都包含一系列的構建步驟。Jenkins可以完成開頭那個場景中所提到的所有驗證工作,它還能更進一步做自動化部署或者一鍵式部署。
我們開始吧, 環境 Windows Server 2012
1. Install Jenkins
http://ftp-nyc.osuosl.org/pub/jenkins/windows/jenkins-1.629.zip
2. Install MsBuild, Git Plugin for Jenkins
GIT client plugin
Shared library plugin for other Git related Jenkins plugins.
GIT plugin
This plugin integrates GIT with Jenkins.
MSBuild Plugin
This plugin makes it possible to build a Visual Studio project (.proj) and solution files (.sln).
SCM API Plugin
This plugin provides a new enhanced API for interacting with SCM systems.
Credentials Plugin
This plugin allows you to store credentials in Jenkins.
插件可以在這兒找到 https://wiki.jenkins-ci.org/display/JENKINS/Plugins
3. Install Git
從官網下載安裝 http://www.git-scm.com/downloads
4. Install .net Framework 4.5.2
官網下載安裝 http://www.microsoft.com/en-us/download/details.aspx?id=42642
5. Install 微軟Build Tools 2013
官網下載安裝 http://www.microsoft.com/en-us/download/details.aspx?id=40760
6. 假設本地已安裝VS2013, 復制本地 C:\Program Files (x86)\MSBuild\Microsoft 下所有文件到服務器相同位置上
筆者是看到是這些文件
打包放置到服務器上面對應路徑。
7. Install Web Deploy v3.0
官網下載安裝 http://www.iis.net/downloads/microsoft/web-deploy
8. Install Artifact Deployer Plugin
This artifact allows you to choose which directories you will like to deploy to the target destination
https://wiki.jenkins-ci.org/display/JENKINS/ArtifactDeployer+Plugin
Jenkins的系統配置
郵件
其它問題
1. 編譯時轉換Web.config文件
例如, 我們需要在Release模式下,替換Web錯誤顯示機制,數據庫連接字符串, 日志文件輸出級別或目錄等配置都可以。
If you add the following xml to the bottom of the .csproj file for your web application, you'll ensure that the config transformation occurs before every build:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> <Target Name="BeforeBuild"> <TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" /> </Target>
Edit: In response to your comment, you should be able to use Web.config as the source parameter in the TransformXml task (see step #2). If you only want to perform the config transform in the build script, follow these instructions:
1) Import WebApplication.targets in your build script like so:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
2) Execute the TransformXml build task in your build script target:
<Target Name="MyBuildScriptTarget"> <TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="Web.config" /> ...other build tasks... </Target>
轉換NLog.config,也可以參考Web.config,實現NLog.Debug.config與Nlog.Release.config, 如下示例的NLog.Release.config文件:
<?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <targets async="true"> <target xdt:Transform="Insert" name="elastic" xsi:type="ElasticSearch" uri="http://10.1.101.54:9200/" index="WebAppInit" documentType="logevent"> <field name="logger" layout="${logger}" layoutType="System.String" /> </target> </targets> <rules> <logger xdt:Transform="Insert" name="*" minlevel="Trace" writeTo="elastic" /> </rules> </nlog>
上面我們在Release模式下,增加了NLog輸出到ElasticSearch的配置節。
2. Microsoft.Build.Tasks.v4.0編譯問題Build Failure issue:
could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Build.Tasks.v4.0.dll". Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Build.Tasks.v4.0.dll
Ideally you should be doing the following:
1) Open your NuGet.targets file: C:\Builds\1\xxxx\FTP Processor (New)\src.nuget\nuget.targets
2) Identify the task referencing the old DLL.
<UsingTask AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" TaskFactory="CodeTaskFactory" >
...
3) Then future proof it like so:
<UsingTask AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll" TaskFactory="CodeTaskFactory" >
...
3. Git中文亂碼問題
進入git安裝目錄,改一下配置就可以基本解決:
etc\gitconfig:
[gui] encoding = utf-8 [i18n] commitencoding = gbk [svn] pathnameencoding = gbk
說明:打開 Git 環境中的中文支持。pathnameencoding設置了文件路徑的中文支持。
4. 資料
源代碼: https://github.com/kohsuke/hudson
總結
持續集成是一種軟件開發實踐,即團隊開發成員經常集成它們的工作,通過每個成員每天至少集成一次,也就意味着每天可能會發生多次集成。每次集成都通過自動化的構建(包括編譯,發布,自動化測試)來驗證,從而盡早地發現集成錯誤。集成軟件的過程不是新問題,如果項目開發的規模比較小,比如一個人的項目,如果它對外部系統的依賴很小,那么軟件集成不是問題,但是隨着軟件項目復雜度的增加(即使增加一個人),就會對集成和確保軟件組件能夠在一起工作提出了更多的要求-要早集成,常集成。早集成,頻繁的集成幫助項目在早期發現項目風險和質量問題,如果到后期才發現這些問題,解決問題代價很大,很有可能導致項目延期或者項目失敗。
本文簡單介紹了持續集成的概念並着重介紹了如何基於 Jenkins 快速構建持續集成環境。通過具體實例的描述,相信讀者對 Jenkins 的基本功能和實現方法有個更清楚地認識和理解。其實,Jenkins 的功能遠不至文中所述的這些,Jenkins 還有詳盡的日志處理和持續集成構建狀態的分析等功能。希望在進一步的學習和應用中與大家分享。
希望對您企業應用開發與企業信息化有幫助。 其它您可能感興趣的文章:
在CentOS上構建.net自動化編譯環境
Jenkins知識地圖
軟件開發的專業化
IT基礎架構規划方案一(網絡系統規划)
IT基礎架構規划方案二(計算機系統與機房規划規划)
IT基礎架構規划方案三(IT基礎軟件和系統規划)
企業應用之性能實時度量系統演變
雲計算參考架構幾例
智能移動導游解決方案簡介
人力資源管理系統的演化
如有想了解更多軟件研發 , 系統 IT集成 , 企業信息化 等資訊,請關注我的微信訂閱號:
作者:Petter Liu
出處:http://www.cnblogs.com/wintersun/
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
該文章也同時發布在我的獨立博客中-Petter Liu Blog。