Storing BizTalk application version via BTDF
The issue
A few weeks ago I saw a very interesting Integration Monday talk session by Toon Vanhoutte which you can view here.
One thing that really stood out for me was how he utilised the BizTalk Deployment Framework (BTDF) BizTalk Application Description field.
We also utilise BTDF and find it a very capable tool for automating the deployment for single BizTalk applications and their related artefacts.
So why would we bother?
If you frequently compile your BizTalk applications (i.e. via automated builds for each check-in) it can be tricky to keep track of which version is deployed in which environment.
So by setting the BizTalk Description field in the BTDF to the following:
<BizTalkAppDescription>Version: $(ProductVersion) - Deployed: $([System.DateTime]::Now.ToString("dd-MM-yyyy HH:mm:ss"))</BizTalkAppDescription>
allows us to easily query it in two ways.
1) We can do it manually via the BizTalk Admin Console.
2) We can utilise BizTalk PowerShell to query it via a script.
ow would we query it via PowerShell?
With BizTalk 2013 and later, you get a copy of BizTalk PowerShell in the folder:
C:\Program Files (x86)\Microsoft BizTalk Server 2013 R2\SDK\Utilities\PowerShell
or alternatively, you can get the latest from codeplex
Ok so I can see this folder. Now what?
First we need to load the module so we can utilise it.
Open up Windows ISE in Administrator mode and run:
Import-Module 'C:\Program Files (x86)\Microsoft BizTalk Server 2013 R2\SDK\Utilities\PowerShell\BizTalkFactory.PowerShell.Extensions.dll'
By default this will create a PSDrive for you. If it doesn’t or you need something specific then you can use the line below to create one for you.
New-PSDrive -Name BizTalk -PSProvider BizTalk -Root BizTalk:\ -Instance . -Database BizTalkMgmtDb -Scope Global
This BizTalk PSDrive is where you can navigate the BizTalk Admin Console like a directory.
Run:
cd Biztalk:\Applications
If you type dir
(or the more accurate PowerShell command Get-ChildItem
), you are likely to get a scrolling list of the properties of your applications.
To get more useful information type:
dir | Select-Object -Property name, description, status
This selects just the name, description and status properties for each Application and displays them on the screen.
This is more like it now, but we still have the Version in a string field. It would be great to isolate that so we can do proper comparisons.
This is where regex comes to the rescue!
Now I know that regex has a very steep learning curve. If you want to learn more about it, I highly recommend checking out and playing around with https://regex101.com. See below for how I was able to determine the regex required for getting the version number out of the string.
So with this knowledge, we can now format the query with slightly more complex PowerShell to look like:
dir | Select-Object Name, @{n='Version';e={([regex]::Match($_.description, '\d+.\d+.\d+.\d+')).Value }},status
Okay. But where would I use this?
Say you use something like Octopus Deploy for your deployment automation. Sure, its UI does have all the versions listed for each application deployed in each environment on display. To confirm the versions that Octopus says is deployed with the versions that actually are deployed, you can do a compare between the version number stored above and what is returned via the Octopus REST API.
I find it ideal to use the Description field to store the Version number and other metadata as it is easily readable by both humans and scripts. :)
Hope this helps other developers or at least gives them some ideas!
Comments