TFS build server搭建,搭建自動化構建服務器

TFS build 服務器的搭建主要步驟以下:api

一:環境準備:服務器

  1. 新建一臺build服務器
  2. 安裝Visual Studio。主要目的是: a. 生成Build腳本所須要的build命令;b.與TFS組合,方便下載最新源代碼
  3. 安裝TFS。在Build Server觸發build時,會經過tfs的命令從源代碼服務器下載最新代碼
  4. 安裝InstallShield。經過InstallShield命令自動打包軟件包
  5. 啓動Visual Studio,手動Mapping源代碼到build server本地目錄。(供源代碼下載使用)

二:腳本代碼的編寫(.bat),如下是bat腳本文件的工做流程app

  1. 啓用Visual Studio tool,這樣就能夠使用visual studio的命令。
  2. 刪除本地的全部代碼
  3. 從服務器下載最新的源代碼
  4. 開始觸發最新源代碼的Build
  5. 開始觸發InstallShield項目的build
  6. 把最新生成的軟件包.exe上傳到某個文件夾備用
  7. checkout 項目源代碼的版本文件並+1,大於9999則從1從新開始。
  8. checkout InstallShield的版本文件並+1
  9. checkin 以上兩個文件,供下次使用。

三:編寫一個計劃任務,自動調用步驟二中的.bat腳本,完成build server的搭建ide

四:代碼示例oop

如下是一個示例,共有兩個文件,一個.bat文件,一個vbs文件。post

.bat文件是整個build腳本的入口,負責總體build server腳本的流程和大部分的工做ui

.vbs文件主要是用來取出文件的版本信息;版本信息加1;並把新的版本號從新寫入存儲版本的文件this

下面是這兩個文件的代碼,部分隱私信息已用*號處理spa

AutoBuildScript:code

@echo off

::Need to manually configure the Path
set VisualStudio2010Tool="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
set SourceCodeItemSpecPath="$/Company_1003/Product/dev/EGS/Product/source/Product/App/eProduct/eProduct-1.7.0/CLK/source/eProduct"
set InstallshieldCommandTool="C:\Program Files (x86)\InstallShield\2012\System\IsCmdBld.exe"
set TeamforgeProjectName="eProduct 1.7"
set TeamforgePackage="eProduct 1.7"


::Relative Path, Manually configure if needed
::SourceCodeFolder e.g. "C:\Code\eProduct1.7\eProduct-1.7.0\CLK\source\eProduct"
set SourceCodeFolder=%~f0\..\..\eProduct
set ForceDownloadLatestSourceCode=True
::BuildSolutionFile e.g."C:\Code\eProduct1.7\eProduct-1.7.0\CLK\source\eProduct\2008sln\eProduct.sln"
set BuildSolutionFile=%~f0\..\..\eProduct\2008sln\eProduct.sln
::BuildModel e.g. Debug or Release
set BuildModel=Release
::eProductDriverProject e.g. "C:\Code\eProduct1.7\eProduct-1.7.0\CLK\source\eProduct\ProductNameeProductDriver\ProductNameeProductDriver.ism"
set eProductDriverProject=%~f0\..\..\eProduct\ProductNameeProductDriver\ProductNameeProductDriver.ism
::TeamforgeUploadExecutableFile e.g. "C:\Data\SFEEUploadFiles\UploadFiles.exe"
set TeamforgeUploadExecutableFile=%~f0\..\SFEEUploadFiles\UploadFiles.exe
::DriverReleaseFilePath e.g. "C:\Code\eProduct1.7\eProduct-1.7.0\CLK\source\eProduct\ProductNameeProductDriver\ProductNameeProductDriver\PROJECT_ASSISTANT\Release 1\DiskImages\DISK1"
set DriverReleaseFilePath="%~f0\..\..\eProduct\ProductNameeProductDriver\ProductNameeProductDriver\PROJECT_ASSISTANT\Release 1\DiskImages\DISK1"
::e.g "C:\Code\eProduct1.7\eProduct-1.7.0\CLK\source\eProduct\libfsl\include\version.h"
set VersionFilePath=%~f0\..\..\eProduct\libfsl\include\version.h
::e.g. "C:\Code\eProduct1.7\eProduct-1.7.0\CLK\source\eProduct\ProductNameeProductDriver\ProductNameeProductDriver.ism"
set DriverFilePath=%~f0\..\..\eProduct\ProductNameeProductDriver\ProductNameeProductDriver.ism
::e.g. C:\Code\eProduct1.7\eProduct-1.7.0\CLK\source\eProduct\ProductNameeProductDriver\ProductNameeProductDriver\PROJECT_ASSISTANT\Interm\IsConfig.ini
set DriverConfigFilePath=%~f0\..\..\eProduct\ProductNameeProductDriver\ProductNameeProductDriver\PROJECT_ASSISTANT\Interm\IsConfig.ini
::e.g. C:\Code\eProduct1.7\eProduct-1.7.0\CLK\source\eProduct\Product\2008win32\
set eProductReleaseFilePath=%~f0\..\..\eProduct\Product\2008win32\
set ModifyVersionVBSFilePath=%~f0\..\autoincreaseversionnumber.vbs
set eProductDriverFilesPath=%~f0\..\..\eProduct\ProductNameeProductDriver\eProductDriverFiles
set eProductDriverCreatePath=%~f0\..\..\eProduct\Product\2008win32\Create

@echo on

echo Set the vs 2010 command tool as the default command prompt.
call %VisualStudio2010Tool%

echo Start to download source code from TFS
if not exist %SourceCodeFolder% ( echo please maping the tfs source code to build server local folder 
echo Build Failed.
exit )
echo Delete the old source code 
rd %SourceCodeFolder%/s/q

echo Downloading source code...
IF %ForceDownloadLatestSourceCode% EQU False (tf get %SourceCodeItemSpecPath% /recursive) ELSE (tf get %SourceCodeItemSpecPath% /all /recursive)
echo Download source code Finished.

echo Start Build the solution
MSBuild %BuildSolutionFile% /property:Configuration=%BuildModel% 
echo Build Finished.

echo Start to build Installshield Project
tf checkout %DriverConfigFilePath%

echo Copy files under Create folder to eProduct Driver installer
rd /s /q %eProductDriverFilesPath%
md %eProductDriverFilesPath%
xcopy /E /F /Y  %eProductDriverCreatePath% %eProductDriverFilesPath%

%InstallshieldCommandTool% -p %eProductDriverProject%
echo Build Installshield Project Finished

echo Start checkout and increase version number, then checkin the increased version number

tf checkout %VersionFilePath% %DriverFilePath%

for /f "delims=" %%i in ('cscript //nologo %ModifyVersionVBSFilePath% %VersionFilePath% %DriverFilePath%') do set "d=%%i"
set TeamforgeVersion=%d%

tf checkin %VersionFilePath% %DriverFilePath% /comment:"Build Server New Build on %TeamforgeVersion%" /noprompt /override:"Build Server Checkin"


echo Start to Upload the Image files to Teamforge
set eProductReleaseUploadFile=%eProductReleaseFilePath%eProduct%TeamforgeVersion%.ZIP
if not exist %eProductReleaseUploadFile% ( echo Do not exist %eProductReleaseUploadFile%, maybe build solution failed. 
echo Build Failed.
exit )

if not exist %DriverReleaseFilePath% ( echo Do not exist %DriverReleaseFilePath%, maybe build Driver Disk failed. 
echo Build Failed.
exit )

%TeamforgeUploadExecutableFile% %eProductReleaseUploadFile% %TeamforgeProjectName% %TeamforgePackage% %TeamforgeVersion% "http://sourceforge.is.ad.Company.com/sf-soap43/services" "Cruise_Control" "Mikohn123"
%TeamforgeUploadExecutableFile% %DriverReleaseFilePath% %TeamforgeProjectName% %TeamforgePackage% %TeamforgeVersion% "http://sourceforge.is.ad.Company.com/sf-soap43/services" "Cruise_Control" "Mikohn123"

echo Upload the Image files to Teamforge Finished

echo Build Finished.

exit
View Code

 

Auto Increase Version Number:

If Wscript.Arguments.Count <> 2 Then
    WScript.Echo "Arguments Count Error"
    wscript.quit
End If


Set objFS = CreateObject("Scripting.FileSystemObject")
'version.h path
versionFilePath=Wscript.Arguments(0)
'ProductNameeProductDriver.ism path
driverFilePath=Wscript.Arguments(1)


Dim newFileContent
Dim newDriverContent
Dim currentVersion
Dim nextVersion

'Manually configure if needed.
'Below 5 variables is used for search the special version number
'This is used for search the postfix number 888 (e.g. 1.7.0.888)
versionPostfixString="#define Product_INT_VERSION "
'This is used for search the prefix string 1.7.0 (e.g. 1.7.0.888)
versionPrefixString="#define PACKAGE_VERSION " & chr(34)
'This is used for search the Product version number in ism file (e.g. 1.7.0.888)
driverProductVersionPrefixString="        <row><td>ProductVersion</td><td>"
'This is used for search the EProduct version number in ism file (e.g. 1.7.0.888)
driverEProductVersionPrefixString="        <row><td>EProductVERION</td><td>"
'the last charactor in the row (ism file)
driverCommonPostfixString="</td><td/></row>"


' Auto Increase version.h file version number
Set versionFile = objFS.OpenTextFile(versionFilePath)
'Read the lines one by one
Do Until versionFile.AtEndOfStream
    strLine = versionFile.ReadLine
    ' Search if this line has versionPostfixString , Then get the postfix number and set the next number: nextVersionPostfix
    If InStr(strLine,versionPostfixString)> 0 Then
        versionPostfixLength=Len(strLine)-Len(versionPostfixString)
        versionPostfix=Right(strLine,versionPostfixLength)
        nextVersionPostfix=versionPostfix+1
        If nextVersionPostfix>=1000 Then
            nextVersionPostfix=1
        End If
        strLine = Replace(strLine,versionPostfix,nextVersionPostfix)
    End If
    'Search if this line has versionPrefixString
    If InStr(strLine,versionPrefixString)> 0 Then
        versionPrefixLength=Len(strLine)-Len(versionPrefixString)
        versionPrefix=Right(strLine,versionPrefixLength)
        versionPrefix=Left(versionPrefix,versionPrefixLength-1)
    End If
    'Store all the lines to newFileContent, it will be write to the version.h again.
    newFileContent = newFileContent & strLine & vbcrlf
Loop
versionFile.Close

'Write the new content to the version.h
Set versionFile  = objFS.OpenTextFile(versionFilePath,2)
versionFile.Write newFileContent
versionFile.Close

currentVersion=versionPrefix & "." & versionPostfix
nextVersion = versionPrefix & "." & nextVersionPostfix

'Auto increase driver version number
Set driverFile = objFS.OpenTextFile(driverFilePath)
'Read the lines one by one
Do Until driverFile.AtEndOfStream
    strLine = driverFile.ReadLine
    ' Search if this line has driverProductVersionPrefixString
    If InStr(strLine,driverProductVersionPrefixString)> 0 Then
        driverPreProductLength=Len(strLine)-Len(driverProductVersionPrefixString)
        driverLastVersionString=Right(strLine,driverPreProductLength)
        driverProductLength=Len(driverLastVersionString)-Len(driverCommonPostfixString)
        driverLastVersionString=Left(driverLastVersionString,driverProductLength)
        strLine = Replace(strLine,driverLastVersionString,nextVersion)
        
    End If

    'Search if this line has driverEProductVersionPrefixString
    If InStr(strLine,driverEProductVersionPrefixString)> 0 Then
        driverPreEProductLength=Len(strLine)-Len(driverEProductVersionPrefixString)
        driverLastEProductVersionString=Right(strLine,driverPreEProductLength)
        driverEProductLength=Len(driverLastEProductVersionString)-Len(driverCommonPostfixString)
        driverLastEProductVersionString=Left(driverLastEProductVersionString,driverEProductLength)
        
        strLine = Replace(strLine,driverLastEProductVersionString,nextVersion)
    End If
    'Store all the lines to newDriverContent, it will be write to the version.h again.
    newDriverContent = newDriverContent & strLine & vbcrlf

Loop
driverFile.Close

'Write the new content to the driver file
Set driverFile  = objFS.OpenTextFile(driverFilePath,2)
driverFile.Write newDriverContent
driverFile.Close

'This is the file version number, return to the result.
WScript.Echo currentVersion
View Code
相關文章
相關標籤/搜索