Back to Top

Publishing and Displaying a Version Number with BuildMaster

It is common to show users of a web site when the site was last published, typically by incrementing a build/revision number, or displaying a "last published" date. There are a variety of ways this can be achieved: from manually updating the date on the web server to reading from external data storage such as a file or database to display the value. With BuildMaster, it can be integrated as part of the build and deploy process.


Let's say our website has one extremely simple page:

   <!DOCTYPE html>
   <html>
   <head>
     <title>Simple Website</title>
   </head>
   <body>
     Version: [[unpublished]]
   </body>
   </html>

On a local workstation, the page outputs exactly what you would expect:

Version: [[unpublished]]

Step 1: Specify server context

Use a General block to set server context this allows you to specify server(s) that will be searched.

Step 2: Add an Action

Now assuming we have an application with a release created in BuildMaster, we just need to add an action that manipulates the file (or files if necessary) to replace any [[unpublished]] placeholders with the actual BuildMaster release & build number.

We can do this with the Search/Replace File Contents operation. When executed, this operation will replace all instances of the specified text with a designated value.

In this case, use a built-in BuildMaster variable combination of $ReleaseNumber.$ReleasePackageNumber. When it comes time for deployment, this variable combination will be replaced with the BuildMaster release number, a literal period, then the current package number. The **.html means that all files and subfiles that are .html will be searched.

In my demonstration plan, I copy the files to the BuildMaster default directory, run the replacement, then copy the replaced file to an "output" directory on my machine.

Step 3: Execute a Build

When you execute a build, the C:\Test\html\example.html file will be copied into the default directory, the [[unpublished]] text will be replaced with the current release & build numbers, and the output will be copied into C:\Test\html-replaced\example.html. Here is a simple diff between the two files that were built under release 6.3, build #3:

Option 2: Use a Date Instead

Use $Date("MM-dd-yyyy") (where MM-dd-yyyy is any valid .NET date/time format string) instead of $ReleaseNumber.$BuildNumber and create a new build:

Text replacements aren't simply limited to simple date replacement; for other ways to perform replacements or even take advantage of Variable Functions, check out the documentation for BuildMaster's built-in variables engine.