Deploy your WebJobs projects with your Azure website using continuous delivery

After sifting through posts, docs, and Stack Overflow, I finally set this up using the same MSBuild process I'm using for Continuous Deployment today. Discussed in detail here. Thanks to the Microsoft.Web.WebJobs.Publish NuGet package, you can now easily extend your csproj build to publish and schedule one or more WebJobs associated with your web app. However, I ran into a bit of trouble dealing with the small and final details of the deployment. So, while I'm finally up and running, I figured this might be worth sharing just in case others are having similar trouble.

First, I'm assuming you have the latest VS tooling installed. We are currently on Update 4, which has the latest RTM tooling for WebJobs. I'm also assuming that you've added a new or associated an existing console app in your solution to your web app using the Add -> Existing Project as Azure WebJob context menu. The tooling is excellent here and will allow you to set up your job's schedule quickly. If you've done all that, you'll have the webjobs-list.json file under Properties in your web project and the webjob-publish-settings.json under Properties in your console app project. If you're not there yet, check out the Getting Started resources.

If you're using VS to publish your app to Azure, that's all you need to do. But since we are talking automation via CI/CD, there are a few more manual steps to follow. There is already a great post on the Azure blog which describes most of the steps you will need to do http://azure.microsoft.com/blog/2014/08/18/enabling-command-line-or-continuous-delivery-of-azure-webjobs/. Most notably, get the publish settings file for the azure sub you are accessing and adding a new file called webjobs.props to the Properties folder. The Microsoft.Web.WebJobs.Publish NuGet package will import this Project file, which allows you to add additional Target elements to feed in your credentials and avoid prompting.

Now for the additional steps that got me the rest of the way

  1. Copy that same webjobs.props file to the exact location in each WebJobs project.
  2. Install the Microsoft.Web.WebJobs.Publish package into each WebJobs project. It should already be installed in the web app project.
  3. Add an additional command to your MSBuild arguments /p:_DestinationType=AzureWebSite. Without that, MSBuild will warn about not publishing to an Azure website and will not complete the job deployments.
  4. Ensure your CI server has all of the latest updates to MSBuild. I accomplished this by applying VS Update 4 to the Express edition I have installed on each agent server. While the MS build tools are now distributed independently, good luck building your projects and getting tool updates without Visual Studio. If you're not current, you'll get a build error when .targets file processes at the end of your build sequence. For reference, I'm using MSBuild v12.

That's it. Now that your solution is set, the following MSBuild call should publish your web app, all WebJobs, and create your schedules, if any were defined in your webjob-publish-settings.

msbuild MyWebApp.csproj /p:Configuration=Debug /p:DeployOnBuild=True 
/p:PublishProfile="MyDevWebsite" 
/p:ProfileTransformWebConfigEnabled=False /p:Password={myPubishPassword} 
/p:AllowUntrustedCertificate=true /p:VisualStudioVersion=12.0 
/p:_DestinationType=AzureWebSite