Jenkins在Windows系統dotnet平臺持續集成

        以前寫過一篇文章是在CentOS上構建.net自動化編譯環境, 今天這篇是針對於Windows平臺的環境。html

       Jenkins是一個開源軟件項目,旨在提供一個開放易用的軟件平臺,使軟件的持續集成變成可能。Jenkins是基於Java開發的一種持續集成工具,用於監控持續重複的工做,git

Jenkins是由Sun的前員工開發的,它的根基是Java,但也能夠用在非Java的項目裏,好比PHP、Ruby on Rails、.NET。持續集成相關的工具備不少。它提供了Web界面,用戶能夠在界面github

上配置Job,每一個Job都包含一系列的構建步驟。Jenkins能夠完成開頭那個場景中所提到的全部驗證工做,它還能更進一步作自動化部署或者一鍵式部署。web

 

咱們開始吧, 環境 Windows Server 2012 數據庫

1. Install Jenkins

http://ftp-nyc.osuosl.org/pub/jenkins/windows/jenkins-1.629.zipwindows

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 下全部文件到服務器相同位置上

筆者是看到是這些文件

image

打包放置到服務器上面對應路徑。

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的系統配置

Git配置
image

MsBuild配置
image

郵件

image

 

其它問題

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.  資料

官網: http://jenkins-ci.org/

源代碼: https://github.com/kohsuke/hudson

 

總結


        持續集成是一種軟件開發實踐,即團隊開發成員常常集成它們的工做,經過每一個成員天天至少集成一次,也就意味着天天可能會發生屢次集成。每次集成都經過自動化的構建(包括編譯,發佈,自動化測試)來驗證,從而儘早地發現集成錯誤。集成軟件的過程不是新問題,若是項目開發的規模比較小,好比一我的的項目,若是它對外部系統的依賴很小,那麼軟件集成不是問題,可是隨着軟件項目複雜度的增長(即便增長一我的),就會對集成和確保軟件組件可以在一塊兒工做提出了更多的要求-要早集成,常集成。早集成,頻繁的集成幫助項目在早期發現項目風險和質量問題,若是到後期才發現這些問題,解決問題代價很大,頗有可能致使項目延期或者項目失敗。
        本文簡單介紹了持續集成的概念並着重介紹瞭如何基於 Jenkins 快速構建持續集成環境。經過具體實例的描述,相信讀者對 Jenkins 的基本功能和實現方法有個更清楚地認識和理解。其實,Jenkins 的功能遠不至文中所述的這些,Jenkins 還有詳盡的日誌處理和持續集成構建狀態的分析等功能。但願在進一步的學習和應用中與你們分享。


但願對您企業應用開發與企業信息化有幫助。 其它您可能感興趣的文章:

在CentOS上構建.net自動化編譯環境
Jenkins知識地圖
軟件開發的專業化
IT基礎架構規劃方案一(網絡系統規劃)
IT基礎架構規劃方案二(計算機系統與機房規劃規劃) 
IT基礎架構規劃方案三(IT基礎軟件和系統規劃)
企業應用之性能實時度量系統演變
雲計算參考架構幾例
智能移動導遊解決方案簡介
人力資源管理系統的演化

若有想了解更多軟件研發 , 系統 IT集成 , 企業信息化 等資訊,請關注個人微信訂閱號:

MegadotnetMicroMsg_thumb1_thumb1_thu[1]


做者:Petter Liu
出處:http://www.cnblogs.com/wintersun/
本文版權歸做者和博客園共有,歡迎轉載,但未經做者贊成必須保留此段聲明,且在文章頁面明顯位置給出原文鏈接,不然保留追究法律責任的權利。
該文章也同時發佈在個人獨立博客中-Petter Liu Blog

相關文章
相關標籤/搜索