0
votes

I'm setting up an automated deployment of a web site in VSTS to Azure using the "Azure Web App Deployment" task. I have set up deployments in the past where the Web App Name was static for a particular target environment, but for this particular project, I'd like for the Web App Name to be calculated (in part) from a property determined at build time: the branch name, via the $(RELEASE_ARTIFACTS_CI_BUILD_SOURCEBRANCHNAME) variable. However, the Web App Name property of the "Azure Web App Deployment" task does not seem to expand server variables - it seems to expect and enforce a static value here.

I've also tried setting the -Name switch under Additional Parameters, but that seems to be overridden by the Web App Name I had to specify.

My question: is it possible to have the Web App Name calculated from server variables at the time of deployment, and if so, how is this done?

2

2 Answers

1
votes

"RELEASE_ARTIFACTS_CI_BUILD_SOURCEBRANCHNAME" is not a Pre-defined variable. So you cannot use it in tasks directly.

Following the steps below if you want use its value in Azure Web app deploy task:

  1. Add a variable in your release definition, for example: "webappname".

  2. Add a "PowerShell Script" task before "Azure Deployment" task, set "Type" to "Inline Script" and enter "Write-Host "##vso[task.setvariable variable=webappname;]$env:RELEASE_ARTIFACTS_LinkedBuildName_SOURCEBRANCHNAME"" in script content. This task will assign the source branch name of the build to "webappname" variable. enter image description here

  3. Now you can use the variable "webappname" in the Azure Deployment task. Enter "$(webappname)" in "Web App Name" of the task. enter image description here