Adventures with Azure DevOps: Assembly Version Validation

I have a .NET 5 Web Api that I deploy using classic pipeline in Azure DevOps.

When my Web Api is published I want to confirm that the correct version was really deployed, sometimes things happen where the deployment is successful but for some reason the older assembly might not be overwritten.

In my Web Api I have a heartbeat action that returns the version number of the assembly, using the C# syntax Assembly.GetExecutingAssembly().GetName().Version.ToString().

My heartbeat action does not require authorization, where the other actions do.

The heartbeat action return a JSON response that include the versionNumber.

Heartbeat Response

Azure DevOps

To set the Web Api build number I followed the steps at Incremental Build Number for .NET Core via Azure DevOps – Edi Wang.

In my Release pipeline, I do the following:

Add AzureRmWebAppDeployment@4 task to deploy my Api to Azure.

Add a PowerShell@2 task to run a PowerShell script to check that my Api was deployed successfully.

I have a PowerShell script that I store in the code repository called ValidateVersion.ps1.

In the Validate version task I update the properties for Script Path and Arguments for my application.

Validate Version Task

Now when my Web Api is deployed, my PowerShell script runs and confirms that the versionNumber provided by the heartbeat action aligns with the Build.BuildNumber that was generated for the artifact.

Is this really necessary?

Maybe not.

The way I look at it though, is it is very little code to ensure the application was deployed correctly before running any further integration or smoke tests, so might save some time and compute.

Thanks for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *