Daily Build Script Sample

These days, I still get query about my article 7 steps of daily build process I posted at the end of 2002. I have not posted to devmanclub.com for a long time. I feel guilty that lots of people are asking for the daily build script I mentioned. I'd like to post the article I wrote two years ago here and share with my readers who are interested in development management processes.

Seven steps of build and release process

1. The builder (part of development team) is primarily responsible for managing the build release.

2. A build is made after the check-in deadline. Typically build will be made at mid-night.

3. The builder creates a share point on a well-known server for releasing the builds. The share point to be used will be //servername/builds [1]

4. Under this share point, each build is released. The process of release would be a copy of all the relevant binaries, files and necessary setup scripts from the build machine to a corresponding directory under the share point. The build release directories would be named as the build number. //servername/builds/buildnumber.[2]

5. The most recent build will always be mapped to the release point of //servername/builds/current [3]. This enables easy location of the current release and also helps in the development of automated scripts by the development and testing community to install the most current build on their test machines etc.

6. At any time, the last 20 will be kept on the build release server. As new builds are released, the old ones falling outside this range will be archived.

7. All key milestone builds will be kept on the release machines until the product is released. The release directories would be appropriately named. For example, //servername/builds/beta1 would contain the Beta1 of the application.

================================================================================

[1] This is a typical file share. Right click a folder in Windows Explorer and select Share…
[2] The folder will be created by build script.
[3] You can archive this using DFS (Distributed File System) that comes with Windows 2000


作者:王建碩
聲明:本腳本及註釋僅代表個人觀點,不代表任何組織或公司。
它以“現狀”提供且沒有任何擔保,同時也沒有授予任何權利
Author: Jian Shuo Wang
Disclaimer: This scripts and comments only represent personal opinion and do not represent any organization or company. This post is provided as-is with no warranties and confers no rights.

整體上講,這個編譯腳本做了幾件事情:
拿到最新的版本
通過更改配置文件把版本號加到DLL中
編譯
把結果拷貝到發佈服務器中指定編譯版本號的目錄中
Basically, the build script did the following things:
Get the latest version of the source code
Add the version number into the DLL by modifying the configuration files
Build
Copy the build result to the folder for the specified build on the release server


我嘗試加入中文註解,並補充行號,以便引用
I added Chinese comment (and English translation) and line numbers, for sake of easy reference

1 @REM ===============================================================================
2 @REM Build script
3 @REM Author: Jian Shuo Wang
4 @REM Created: 12:04 PM 3/12/2002
5 @REM Modified:
6 @REM 1.1 SD Label added at 12:04 PM 3/12/2002
7 @REM 1.2 Fix the bug to delete .css file from release server
8 @REM 1.3 Add version numbers to both DLLs and web page
9 @REM 1.4 Added facade server and moved all webclient
10 @REM to web folder.
11 @REM 1.5 Fixed bug 258 [Build] Build script doesn't provide label description
12 @REM 1.6 Reorged the folder and added WinUI to builds]
13 @REM 1.7 Add build number to all EXEs and DLLs
14 @REM 1.8 Depress prompt by echo D to web.config.
15 @REM
16 @REM
17 @REM ===============================================================================
18

編譯腳本的變化有可能產生編譯結果的變化或產生新的Bug,編譯腳本也可能產生Bug,所以編譯腳本的也要有版本號
Changes of build script may affect the compile result or cause new bug. There may be bugs in the build script itself. So we need to give a version to the build script.

19 @SET BuildScriptVersion=1.8
20
21 @REM ===============================================================================
22 @REM Usage:
23 @REM copybuilds.bat
24 @REM is the revision number. In case you need
25 @REM to create a build with revision number other
26 @REM then 0, you can use
27 @REM copybuilds.bat 1
28 @REM to create builds like 2295.1
29 @REM ===============================================================================
30

建議Build號的格式:
a.b.cccc.d, 如2.0.2533.0
a - 主版本號
b - 副版本號
cccc - 每日編譯號
d - 更新號
主副版本號在一個產品大的發佈之前不變,每日編譯號每天加一 (注意,開始值不一定爲1,建議爲一個隨機的4位數,這樣保證它的位數一直是4位,方便引用。
Suggested Build Number Format:
a.b.cccc.d, eg: 2.0.2533.0
a - Major Build Number
b - Minor Build Number
cccc - Daily Build Number
d - Revision number

每日編譯腳本每天自動運行,不過有時當出現Build break (自動運行/編譯失敗),或BVT測試沒有通過, 可能會臨時產生新的版本,這很少見,但一旦發生,可以手動運行編譯腳本,並指派更新號。如果一天有多個build, 他們會有不同的更新號,比如 2.0.2533.1, 2.0.2533.2....
Daily build runs daily automatically. However, when Build Break (auto run/build failure) happens, or BVT (Build Verification Test) does not pass, it is possible to create some temporary new build. This is rare. But when it does happen, we can run the build script manually and assign a new revision number. If there are more than one build on the same day, they have different revision number, for example, 2.0.2533.1, 2.0.2533.2....

31 @SET BuildRev=0
32
33 @REM ===============================================================================
34 @REM This script is extended to be used on sha-jswang-02 exclusively
35 @REM ===============================================================================
36
37 @REM ===============================================================================
38 @REM Define variables
39 @REM ===============================================================================
40

定義一些變量,因爲編譯腳本基本上只會在編譯服務器上運行,所以很多東西直接寫到Code裏了。編譯服務器可以使團隊中配置最差的機器,或利用率最低的機器,最好保證沒有人在上面編程,否則不小心更改了設置就會產生Build環境改變,就可能會改變最終的編譯結果。
Define some variables. Since the daily build script generally only runs on the build machine, we can hard code a lot of places into the script. It is OK to use the most poorly configured machine in the team, or a computer with lowest utilization. It is important that nobody develops on it. Otherwise, the developer may change the configuration that causes Build environment change, so to change the final result of the daily build.

41 @PATH=c:/program files/Microsoft Visual Studio .NET/Common7/IDE;%PATH%;
42 @SET SCRIPTROOT=C:/WebRaid
43 @SET SDROOT=C:/webraid/workplace
44
45 @SET SLNROOT=C:/webraid/workplace/src/RAID
46 @SET WEBUIROOT=C:/webraid/workplace/src/RAID/RAID_WEBUI
47 @SET WINUIROOTDEBUG=C:/webraid/workplace/src/RAID/WinUI/bin/Debug
48 @SET WINUIROOTRELEASE=C:/webraid/workplace/src/RAID/WinUI/bin/Release
49 @SET RELEASESERVER=//sha-calvin/WebRAID/builds/
50 @SET WINUIROOTRELEASE=C:/webraid/workplace/src/RAID/WinUI/bin/Release
51 @SET BUILDREPORT=%SCRIPTROOT%/BuildReport.txt
52
53 @REM ===============================================================================
54 @REM Database related variables
55 @REM ===============================================================================
56
57 @SET MASTER_DB_SERVER=steven02
58 @SET MASTER_DB_SA=sa
59 @SET MASTER_DB_PASSWORD=123
60 @SET BCPCMD=-U"%MASTER_DB_SA%" -P"%MASTER_DB_PASSWORD%" -S "%MASTER_DB_SERVER%"
61
62 @REM ===============================================================================
63 @REM Generate build numbers, SD Labels.
64 @REM ===============================================================================
65
66 @CSCRIPT //NoLogo %SCRIPTROOT%/GenBuildNo.vbs > %SCRIPTROOT%/SetBuildNo.bat
67 @CALL %SCRIPTROOT%/SetBuildNo.Bat
68
69 @SET SDLABEL=build%BuildNo%
70 @SET BuildName=%BuildNo%
71
72 @REM ===============================================================================
73 @REM Check whether is is parameter for this script
74 @REM ===============================================================================

就在這裏加更新號
Add build revision number here.

75
76 @If A%1A==AA goto :Continue
77 @SET BUILDRev=%1
78 @SET SDLABEL=build%BuildNo%.%BuildRev%
79 @SET BuildName=%BuildNo%.%BuildRev%
80 :Continue
81
82

準備編譯報告。編譯報告要存放到該Build所在的目錄,以便以後瞭解Build時的情況
Prepare compile report. Compile report should be saved into the folder of the build, so you know the situation when the build was created.

83
84 @ECHO ===============================================================================
85 @ECHO P E C K E R B U I L D S C R I P T V %BuildScriptVersion%
86 @ECHO ===============================================================================
87 @ECHO.
88 @ECHO Build Number: %BuildName%
89 @ECHO.
90
91 @REM ===============================================================================
92 @REM BUILD REPORT
93 @REM ===============================================================================
94
95 @ECHO ======================================== > %BuildReport%
96 @ECHO Build Report for Build %BuildName% >> %BuildReport%
97 @ECHO Build Script Version: %BuildScriptVersion% >> %BUILDREPORT%
98 @ECHO Builder: Jian Shuo Wang (jswang) >> %BUILDREPORT%
99 @ECHO Start Build: >> %BUILDREPORT%
100 @Date /T >> %SCRIPTROOT%/buildreport.txt
101 @TIME /T >> %SCRIPTROOT%/buildreport.txt
102
103 @REM ===============================================================================
104 @REM Get the latest source
105 @REM ===============================================================================
106
107 @C:
108 @CD %SDROOT%
109

我的這個例子中用的是自己的一個工具,VSS有自己的命令行參數
I am using our own tool in this sample. Visual SourceSafe has its own command line parameter.

110
111 @ECHO ===============================================================================
112 @ECHO Retrieving source code from SD Server
113 @ECHO ===============================================================================
114 @ECHO Please wait ...
115
116 SD sync -f src... > NUL
117 @ECHO.
118

建立Label,就是把產生這個版本的所有文件的當前版本記錄下來,一旦以後某天需要恢復到這個版本,只需把代碼同步到這個標籤就可以了,然後我們就能保證從源代碼樹中編譯出來任何制定的版本。
Create Label, which is a record of all the version numbers of the used files that generates this build, in case one day, we need to restore this build from the source code. We can do a label synchronization to make sure we can build out the certain build from the source code tree.

119 @REM ===============================================================================
120 @REM Create label
121 @REM ===============================================================================
122
123 @REM Create Labels
124 @ECHO OFF
125 @ECHO Label: %SDLABEL% >%WEBUIROOT%/Temp.txt
126 @ECHO Owner: FAREAST/jswang >>%WEBUIROOT%/Temp.txt
127 @ECHO Description: >>%WEBUIROOT%/Temp.txt
128 @ECHO Build Number %BuildName% >>%WEBUIROOT%/Temp.txt
129 @ECHO Options: unlocked >>%WEBUIROOT%/Temp.txt
130 @ECHO View: >>%WEBUIROOT%/Temp.txt
131 @ECHO //depot/... >>%WEBUIROOT%/Temp.txt
132
133 Type %WEBUIROOT%/Temp.txt | SD label -i
134
135 @ECHO ===============================================================================
136 @ECHO Synchronizing label
137 @ECHO ===============================================================================
138 @ECHO Please wait ...
139
140 SD labelsync -l %SDLABEL%
141
142 DEL %WEBUIROOT%/Temp.txt
143
144

正式開始編譯。 我會產生一個release版,一個Debug版
Finally, starts to compile. I will generate a RELEASE version a DEBUG version.

145
146
147
148
149
150
151 @REM ===============================================================================
152 @REM Begin to build
153 @REM ===============================================================================
154
155 @REM ===============================================================================
156 @REM Change the version number for DLLs
157 @REM ===============================================================================
158
159 @ECHO ===============================================================================
160 @ECHO Adding build number to DLLs
161 @ECHO ===============================================================================
162
163 Call %SCRIPTROOT%/AddBuildNumber.bat %SLNROOT%/SystemFrameworks/AssemblyInfo.cs
164 Call %SCRIPTROOT%/AddBuildNumber.Bat %SLNROOT%/Common/AssemblyInfo.cs
165 Call %SCRIPTROOT%/AddBuildNumber.Bat %SLNROOT%/DataAccess/AssemblyInfo.cs
166 Call %SCRIPTROOT%/AddBuildNumber.Bat %SLNROOT%/RAID_WebUI/AssemblyInfo.cs
167 Call %SCRIPTROOT%/AddBuildNumber.Bat %SLNROOT%/BusinessFacade/AssemblyInfo.cs
168 Call %SCRIPTROOT%/AddBuildNumber.Bat %SLNROOT%/WindowsControl/AssemblyInfo.cs
169 Call %SCRIPTROOT%/AddBuildNumber.Bat %SLNROOT%/WinUI/AssemblyInfo.cs
170
171
172 @REM ===============================================================================
173 @REM Add Version Number to Default.aspx
174 @REM ===============================================================================
175
176 Attrib -R %WEBUIROOT%/Default.aspx
177 Type %SCRIPTROOT%/VersionSpanStart.txt >> %WEBUIROOT%/Default.aspx
178 @ECHO Build %BuildName% >> %WEBUIROOT%/Default.aspx
179 Type %SCRIPTROOT%/VersionSpanEnd.txt >> %WEBUIROOT%/Default.aspx
180
181 @REM ===============================================================================
182 @REM Build debug version
183 @REM ===============================================================================
184
185 @ECHO ===============================================================================
186 @ECHO Begin to Build Debug Version %BuildName%
187 @ECHO ===============================================================================
188 @ECHO It may take 1-2 minutes. Please wait ...
189
190 DEVENV %SLNROOT%/RAID.SLN /rebuild "debug" >> %BUILDREPORT%
191
192 @ECHO Build completed
193 @ECHO.
194
195 @ECHO ===============================================================================
196 @ECHO Begin to Build Release Version %BuildName%
197 @ECHO ===============================================================================
198 @ECHO It may take 1-2 minutes. Please wait ...
199
200 DEVENV %SLNROOT%/RAID.SLN /rebuild "release" >> %BUILDREPORT%
201
202 @ECHO Build completed
203 @ECHO.
204
205
206 @ECHO ===============================================================================
207 @ECHO Begin to Build Release Version of WindowsControl %BuildName%
208 @ECHO ===============================================================================
209 @ECHO It may take 1-2 minutes. Please wait ...
210
211 DEVENV %SDROOT%/src/WindowsControl.T/WindowsControl.sln /rebuild "release" >> %BUILDREPORT%
212
213 @ECHO Build completed
214 @ECHO.
215

把開發現狀的數據庫結構Dump成SQL語句, 以便安裝程序可以完整的復原開發現狀
Dump the existing database structure into SQL scripts, so that setup program can restore the database

216
217 @REM ===============================================================================
218 @REM D A T A B A S E S E T U P
219 @REM
220 @REM The following script is provide by Jian Wu. It uses bcp tool to get all the
221 @REM data in the SQL Database and put it in files with .db.txt extension.
222 @REM ===============================================================================
223
224 @ECHO ===============================================================================
225 @ECHO Dumping databases
226 @ECHO ===============================================================================
227
228 bcp "GTECRAID.dbo.Alias" out "%SCRIPTROOT%/Alias.db.txt" -c %BCPCMD%
229 bcp "GTECRAID.dbo.BugStore" out "%SCRIPTROOT%/BugStore.db.txt" -c %BCPCMD%
230 bcp "GTECRAID.dbo.FldItems" out "%SCRIPTROOT%/FldItems.db.txt" -c %BCPCMD%
231 bcp "GTECRAID.dbo.Flds" out "%SCRIPTROOT%/Flds.db.txt" -c %BCPCMD%
232 bcp "GTECRAID.dbo.Links" out "%SCRIPTROOT%/Links.db.txt" -c %BCPCMD%
233 bcp "GTECRAID.dbo.LinkTokens" out "%SCRIPTROOT%/LinkTokens.db.txt" -c %BCPCMD%
234 bcp "GTECRAID.dbo.NotificationRules" out "%SCRIPTROOT%/NotificationRules.db.txt" -c %BCPCMD%
235 bcp "GTECRAID.dbo.StaticWebPart" out "%SCRIPTROOT%/StaticWebPart.db.txt" -c %BCPCMD%
236 bcp "GTECRAID.dbo.Tabs" out "%SCRIPTROOT%/Tabs.db.txt" -c %BCPCMD%
237 bcp "GTECRAID.dbo.TabWebParts" out "%SCRIPTROOT%/TabWebParts.db.txt" -c %BCPCMD%
238 bcp "GTECRAID.dbo.[User]" out "%SCRIPTROOT%/User.db.txt" -c %BCPCMD%
239 bcp "GTECRAID.dbo.UserAlias" out "%SCRIPTROOT%/UserAlias.db.txt" -c %BCPCMD%
240 bcp "GTECRAID.dbo.UserQueryStore" out "%SCRIPTROOT%/UserQueryStore.db.txt" -c %BCPCMD%
241 bcp "GTECRAID.dbo.WebParts" out "%SCRIPTROOT%/WebParts.db.txt" -c %BCPCMD%
242

編譯完成,開始拷貝編譯出來的二進制文件
Compile completed. Start to copy the binary outcome of the compilation

243
244 @REM ===============================================================================
245 @REM Begin to copy files to release server
246 @REM ===============================================================================
247
248
249 @REM ===============================================================================
250 @REM A T T E N T I O N ON A P P S E R V E R S E T U P
251 @REM
252 @REM The builder moved the file web.config from Pecker_Facade folder to
253 @REM setup folder and rename it to server.web.config during the setup.
254 @REM This helps to reduce the complexity
255 @REM of the code by reducing the number of folder needed. The setup script
256 @REM will re-build the server folder and move the web.config file there.
257 @REM
258 @REM C H A N G E S
259 @REM
260 @REM THE NOTE ABOVE IS NOT LONG VALID. I have setup a new folder named
261 @REM "Sever" in the root folder of the distribution disk that holds all server
262 @REM DLLs and configuration information
263 @REM ===============================================================================
264
265 @ECHO ===============================================================================
266 @ECHO Copying AppServer Debug Version
267 @ECHO ===============================================================================
268
269 ECHO D | XCOPY %WEBUIROOT%/../PECKER_FACADE/web.config %RELEASESERVER%%BUILDName%/Debug/Server /I /S /Y
270 XCOPY %WEBUIROOT%/bin %RELEASESERVER%%BUILDName%/Debug/Server/Bin /S /Y /I
271
272 @ECHO ===============================================================================
273 @ECHO Copying AppServer Release Version
274 @ECHO ===============================================================================
275
276 ECHO D | XCOPY %WEBUIROOT%/../PECKER_FACADE/web.config %RELEASESERVER%%BUILDName%/Release/Server /I /S /Y
277 XCOPY %WINUIROOTRELEASE%/*.DLL %RELEASESERVER%%BUILDName%/Release/Server/Bin /S /Y /I
278
279
280 @ECHO ===============================================================================
281 @ECHO Copying Database Data
282 @ECHO ===============================================================================
283
284 XCOPY %SCRIPTROOT%/*.db.txt %RELEASESERVER%%BUILDName%/Debug/Database /S /Y /I
285 XCOPY %SCRIPTROOT%/*.db.txt %RELEASESERVER%%BUILDName%/Release/Database /S /Y /I
286 Del %SCRIPTROOT%/*.db.txt
287
288 XCOPY %WEBUIROOT%/../PECKER_FACADE/database.sql %RELEASESERVER%%BUILDName%/Release/Database /I /S /Y
289 XCOPY %WEBUIROOT%/../PECKER_FACADE/database.sql %RELEASESERVER%%BUILDName%/Debug/Database /I /S /Y
290
291 @ECHO ===============================================================================
292 @ECHO Copying WebUI Debug Version
293 @ECHO ===============================================================================
294
295 XCOPY %WEBUIROOT% %RELEASESERVER%%BUILDName%/Debug/Web /S /EXCLUDE:%SCRIPTROOT%/Excludelist.txt /Y /I
296 COPY %WEBUIROOT%/*.css %RELEASESERVER%%BUILDName%/Debug/Web
297
298 @ECHO ======================================== >> %BUILDREPORT%
299 @ECHO Copy WebUI Debug Ends: >> %BUILDREPORT%
300 Date /T >> %BUILDREPORT%
301 TIME /T >> %BUILDREPORT%
302
303 @ECHO ===============================================================================
304 @ECHO Copying WebUI Release Version
305 @ECHO ===============================================================================
306
307 XCOPY %WEBUIROOT% %RELEASESERVER%%BUILDName%/Release/Web /S /EXCLUDE:%SCRIPTROOT%/Excludelist.txt /Y /I
308 COPY %WEBUIROOT%/*.css %RELEASESERVER%%BUILDName%/Release/Web
309
310 @ECHO ======================================== >> %BUILDREPORT%
311 @ECHO Copy WebUI Release Ends: >> %BUILDREPORT%
312 Date /T >> %BUILDREPORT%
313 TIME /T >> %BUILDREPORT%
314
315
316 @ECHO ===============================================================================
317 @ECHO Copying WinUI Debug Version
318 @ECHO ===============================================================================
319
320 XCOPY %WINUIROOTDEBUG% %RELEASESERVER%%BUILDName%/Debug/Win /S /EXCLUDE:%SCRIPTROOT%/Excludelist.txt /Y /I
321 COPY %WINUIROOTDEBUG%/../../help/*.chm %RELEASESERVER%%BUILDName%/Debug/Win /Y
322
323 @ECHO ======================================== >> %BUILDREPORT%
324 @ECHO Copy WinUI Debug Ends: >> %BUILDREPORT%
325 Date /T >> %BUILDREPORT%
326 TIME /T >> %BUILDREPORT%
327
328 @ECHO ===============================================================================
329 @ECHO Copying WinUI Release Version
330 @ECHO ===============================================================================
331
332 XCOPY %WINUIROOTRELEASE% %RELEASESERVER%%BUILDName%/Release/Win /S /Y /I
333 XCOPY %WINUIROOTDEBUG%/WinUI.exe.xml %RELEASESERVER%%BUILDName%/Release/Win /I /S /Y
334 COPY %WINUIROOTRELEASE%/../../help/*.chm %RELEASESERVER%%BUILDName%/Release/Win /Y
335
336 Copy %SDROOT%/src/WindowsControl.T/bin/Release/WindowsControl.dll %RELEASESERVER%%BUILDName%/Release/Win/WindowsControl.dll /Y
337
338 @ECHO ======================================== >> %BUILDREPORT%
339 @ECHO Copy WinUI Release Ends: >> %BUILDREPORT%
340 Date /T >> %BUILDREPORT%
341 TIME /T >> %BUILDREPORT%
342
343

開發過程中有簡易的Setup.bat保證可以在一個嶄新的機器上安裝最終程序,這保證了測試的起點是一樣的
Simple setup.bat to install the compiled build onto a new machine. This ensures the starting point of the test is identical every time you setup.

344
345
346
347 @ECHO ===============================================================================
348 @ECHO Moving the setup.bat script
349 @ECHO ===============================================================================
350
351 Move %RELEASESERVER%%BUILDName%/Debug/Web/Setup.bat %RELEASESERVER%%BUILDName%/Debug
352 Move %RELEASESERVER%%BUILDName%/Release/Web/Setup.bat %RELEASESERVER%%BUILDName%/Release
353
354
355 @ECHO ===============================================================================
356 @ECHO Copy the build report to release server
357 @ECHO ===============================================================================
358
359 Copy %BUILDREPORT% %RELEASESERVER%%BUILDName%
360

大功告成
Mission completed

361
362 @ECHO ===============================================================================
363 @ECHO Build completed successfully
364 @ECHO ===============================================================================

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章