Passing An Azure Staging Slot URI To A Test Runner In Visual Studio Team Services Release Management

July 12 2016

I wanted to run our coded ui tests using Selenium against the staging uri during our continuous integration workflow of our cloud service web role. But the problem arose that I didn’t know the dynamically generated URI that gets created by Azure when deploying to the staging slot.

I chatted with DevOps guru Thiago Almeida about this and he had the following suggestion:

Add a Powershell script between the publish step and the test step.  Here’s what the Powershell looked like:

$deployment = Get-AzureDeployment -ServiceName service_name -Slot Staging

if ($deployment -eq $null)

{

   write-host "No deployment is detected. "

   //Throw an exception for the build to fail here…

}

else

{

   $deploymentUrl = $deployment.Url

   # As explained here this next line creates a new variable with the value that other tasks can use https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md

   Write-Host ("##vso[task.setvariable variable=StagingWebsiteURL;]$deploymentUrl")

}

 

To use this, you’ll need to change the service_name to your Azure service name.

Then, on the Test Assemblies task’s “Override TestRun Parameters” value, update it to this to set the base URL to be the value of the variable set in the PowerShell task above:

webAppUrl=$(StagingWebsiteURL)

 

Nice! It totally worked! Tip of the hat to Thiago Almeida for suggesting this!