Deploy from TeamCity to Azure Using Web Deploy
Although Git-based continuous deployment of my site to Azure seemed like a good idea, it turned out too unreliable. As the site grew, deployments started failing more and more frequently with a very non-descriptive error:
An unknown error has occurred. Check the diagnostic log for details.
Neither the continuous deployment log nor the diagnostic log contained any additional information. I suspected it was happening because the build was taking too long to complete, but I didn't manage to get to the bottom of the issue. Instead I started exploring the alternatives.
Since my TeamCity continuous integration server was already building and validating the site before triggering the deployment by merging to a new branch, I decided to use it for deployment to Azure as well. There are several deployment options available that are suitable for a build server. I decided to use Web Deploy, because it is reasonably easy to set up and it also supports deleting of removed files from the deployment location.
Making it work in TeamCity required only one additional command line build step at the end of my build configuration (of course Web Deploy extension needs to be installed first):
- Command executable:
"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
- Command parameters:
-verb:sync -source:contentPath="%teamcity.build.checkoutDir%\out" -dest:contentPath='%azureSite%',ComputerName="https://%azurePublishUrl%/msdeploy.axd?site=%azureSite%",UserName='%azureUsername%',Password='%azurePassword%',AuthType='Basic'
You can notice, I introduced TeamCity parameters for all non-fixed values in msdeploy.exe
parameters. This has several advantages:
- I don't need to repeat values which appear multiple times.
- It will be easier for me to change the values in the future, if necessary.
- I could create a Meta-Runner for the step if I wanted to use it in other build configurations.
I defined the parameters at the build configuration level as Configuration Parameters. The values can be easily extracted from the publish profile (I replaced the actual values with TeamCity parameter placeholders):
<publishProfile profileName="damirscorner - Web Deploy"
publishMethod="MSDeploy"
publishUrl="%azurePublishUrl%"
msdeploySite="%azureSite%"
userName="%azureUsername%"
userPWD="%azurePassword%"
destinationAppUrl=""
SQLServerDBConnectionString=""
mySQLDBConnectionString=""
hostingProviderForumLink=""
controlPanelLink=""
webSystem="WebSites">
<databases />
</publishProfile>
Publish profile can be downloaded from the wep app toolbar in the Azure portal.