Querying Azure Web Apps Version Number

2019-05-28 13:30发布

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?

1条回答
来,给爷笑一个
2楼-- · 2019-05-28 14:18

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:

  1. Add azure PowerShell task to call Get-AzureRMWebAppSlot to get the AppSettings and compare with current build number
  2. If they are different, you can deploy the package to azure through Azure WebApp Deployment task
  3. Add azure PowerShell task to call Set-AzureRMWebAppSlot to update the AppSettings.

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.

查看更多
登录 后发表回答