標籤:
之前寫過一篇文章是在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的系統配置
Git配置
MsBuild配置
郵件
其它問題 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 還有詳盡的Tlog和持續整合構建狀態的分析等功能。希望在進一步的學習和應用中與大家分享。
希望對您公司專屬應用程式開發與公司資訊化有協助。 其它您可能感興趣的文章:
在CentOS上構建.net自動化編譯環境
Jenkins知識地圖
軟體開發的專業化
IT基礎架構規劃方案一(網路系統規劃)
IT基礎架構規劃方案二(電腦系統與機房規劃規劃)
IT基礎架構規劃方案三(IT基礎軟體和系統規劃)
公司專屬應用程式之效能即時度量系統演變
雲端運算參考架構幾例
智能移動導遊解決方案簡介
人力資源管理系統的演化
如有想瞭解更多軟體研發 , 系統 IT整合 , 公司資訊化 等資訊,請關注我的訂閱號:
Petter Liu
出處:http://www.cnblogs.com/wintersun/
本文著作權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文串連,否則保留追究法律責任的權利。
該文章也同時發布在我的獨立部落格中-Petter Liu Blog。
Jenkins在Windows系統dotnet平台持續整合