We are deploying to Azure Web App slots using VSTS. We want a way for the website to know its build number for versioning purpose.
We thought of setting the VSTS build as an environment variable during the release process as the Azure Web App website has access to the environment variable.
And we also noticed that VSTS warns you before releasing to VSTS that you are releasing the same build again, so there must be a way that VSTS is querying Azure Web App for this.
- Is there a standard way of knowing the build version from within the website?
- If not, is there a better way of querying the version number other than having an environment variable during the release?
If you just want to use the build number in you web app (e.g. display in a page), you can store the build number in the configuration file, such as web.config, appsettings.json, then read the value in your code.
To store the build number in configuration file, you can do it by using Replace Token task before visual studio build task in build definition.
If you want to use the build number in additional task, for example compare current build number with the current app service build number, you can store the build number in AppSettings of azure app service. Simple workflow:
There is the blog: Accessing/Updating Azure Web App Settings from VSTS using Azure PowerShell
BTW: You can get the current build number through Build.BuildNumber variable in Build/Release.