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 ===============================================================================
如有任何疑问,欢迎跟贴
Comments are welcome.
王建硕[微软]
本贴子以”现状”提供且没有任何担保,同时也没有授予任何权利
Jian Shuo Wang [Microsoft]
This post is provided as-is with no warranties and confers no rights.