Examples of how to use Build version (buildver) for Windows.

Build script with backup of each build

This example shows how buildversion is used twice in a potential build script. It is called first time to increment the build number before the build process startes. Then again in the end to fetch the build number in order to create a backup using rar. We added some pre and post arguments to get the output to look more meaningful, and we used only the build number in the end to create a unique backup file each time.

build.bat:

@ECHO OFF
SET PROJECTNAME=bananaboat
SET BUILDVER=
REM ---- Starting the build process here ----
buildver.exe --preout "%PROJECTNAME% build " --postout " %CD%"
ECHO ***building***
REM ---- Archive this build ----
FOR /F "tokens=*" %%x in ('buildver.exe --show --clean') do SET BUILDVER=%%x
ECHO Now archiving this build using rar under local directory "\backup"
rar a -m5 "backup\%PROJECTNAME%_build_%BUILDVER%.rar" > "backup\%PROJECTNAME%_build_%BUILDVER%.rar.log"
ECHO ..All done

output:

C:\projects\tommy\test>build.bat
bananaboat build 0037 (2014-06-10 10:05:44 tommy@pc2.pc2) c:\projects\tommy\test
***building***
Now archiving this build using rar under local directory "\backup"
..All done

C:\projects\tommy\test>dir backup

10/06/2014  10:08 AM    <DIR>          .
10/06/2014  10:08 AM    <DIR>          ..
09/06/2014  11:22 PM             2,719 bananaboat_build_0035.rar.log
09/06/2014  11:22 PM           171,610 bananaboat_build_0035.rar
10/06/2014  09:26 AM             2,719 bananaboat_build_0036.rar.log
10/06/2014  09:26 AM           171,612 bananaboat_build_0036.rar
10/06/2014  10:08 AM             2,719 bananaboat_build_0037.rar.log
10/06/2014  10:09 AM           171,611 bananaboat_build_0037.rar

Creating a log file with all build versions

A simple example showing how to create a log file in a different location that contains a list of all builds.

build.bat:

@ECHO OFF
SET PROJECTNAME=Alpha
SET PROJECT_PATH=C:\project\alpha
SET BUILD_PATH=C:\project\alpha\datafiles
buildver.exe --path "%BUILD_PATH%" --preout "%PROJECTNAME% build " --postout " %CD%"
rem ---- Append to project build log file ----
buildver.exe --path "%BUILD_PATH%" --show >> "%PROJECT_PATH%\build.version.log"

output:

C:\project\alpha>build.bat
Alpha build 0118 (2014-06-10 10:18:17 tommy@pc2.pc2) C:\project\alpha

C:\project\alpha>type "C:\project\alpha\build.version.log"
0115 (2014-06-09 23:17:42 tommy@pc2.pc2)
0116 (2014-06-09 23:17:55 tommy@pc2.pc2)
0117 (2014-06-09 23:17:57 tommy@pc2.pc2)
0118 (2014-06-10 10:18:17 tommy@pc2.pc2)

C:\project\alpha>

Script to deploy a website using ftp

This is a more advanced script that will update the build number for this project, create a backup of the files, and upload all the files recursivly using ftp.

The parent folder name "test3" is used as the project name, and the folder "www" contains the actual files being deployed. The comments in the deploy.bat example below explains the different steps. The site.cfg is config file containing ftp address and login details for NcFTP.

In previous example we used "build.version.log" to keep a history of all the builds, in this case we renamed the file to "deploy.log" and it now provides us with a history of all the deployed versions.

Note that the example below is simplified and does not check for any errors. Altough this script could be used to automatically deploy to a staging server, I would recommend some human interaction if you consider deploying to a live server.

figure.1

deploy.bat:

@ECHO OFF

REM use current directory name as the projectname
FOR /f "delims=\" %%a in ("%cd%") do SET PROJECTNAME=%%~nxa

ECHO --------------------------- DEPLOYING ---------------------------

REM Update build version on www folder, and get the buildnumber into buildver.
SET BUILDVER=
buildver.exe --path "%cd%\www" --preout "%PROJECTNAME% build "
FOR /F "tokens=*" %%x in ('buildver.exe --path "%cd%\www" --show --clean') do SET BUILDVER=%%x

REM Uses rar command line version from RARLAB (http://www.rarlab.com)
REM Create a backup of the build before we deploy using rar, and log output..
rar a -m5 "backup\%PROJECTNAME%_build_%BUILDVER%.rar" > "backup\%PROJECTNAME%_build_%BUILDVER%.rar.log"

REM Uses NCFTP from NcFTP Software Inc. (http://www.ncftp.com/)
REM Deploy the folder www recursivly using ftp..
SET NCFTP=%ProgramFiles%\NcFTP Software\NcFTP
"%NCFTP%\ncftpput.exe.lnk" -f site.cfg -R /  www

REM Update the deploy.log with new entry.
buildver.exe --path "%cd%\www" --show >> deploy.log

output: (notice the build version file is also uploaded.)

L:\test3>deploy.bat
--------------------------- DEPLOYING ---------------------------
test3 build 0015 (2014-06-10 11:27:35 tommy@pc2.pc2)

www\test2.txt:                                           5.00 B   160.00 B/s
www\build.version.0015:                                 40.00 B     2.50 kB/s
www\test\test.file:                                      5.00 B   320.00 B/s

L:\test3>
Site maintained by tommy@trapv.com.
Page generated in: 0.0184 seconds.
Memory usage: 427960 bytes (peak: 476368 bytes)