Deploying and Schedule Azure WebJobs from VSTS to Azure Web App (With bonus CRON Scheduling)
WebAPI apps with WebJobs schedules are currently the intuitive way to work with Web Apps.
In this article, I am going to show you how to deploy a WebApp along with Web Jobs, and as an added bonus, use Azure’s internal CRON Scheduler to schedule the WebJobs. Sweet! Let’s get started.
We already have this blog that shows how to publish a Web App from VSTS. We’ll expand on that.
Add a New Azure WebJob Project
You could set up the schedule for this,
This creates a webjob-publish-settings.json file
This will use Azure Scheduler Services to schedule the job.
Going back to our build definition from this, let’s add another task for Azure Web App Deployment for the WebJob,
Modify the MSBuild Arguments as follows, removing, [/p:PackageAsSingleFile=true].
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.stagingDirectory)"
So, in the artifact drop, we will get 2 WebDeploy Packages, one for the Web App and the other for Web Job.
We should be good to go, let’s queue a build.
Post build, you’ll notice that separate zip files are created,
Let’s check our Web App on Azure Portal,
Simple as that, the WebJob automatically is placed under the appropriate place, automatically.
BONUS! (Using CRON Scheduler)
If you’re familiar with the CRON Scheduler, or want more flexibility in scheduling, Azure has an internal CRON Scheduler, that can be used, https://azure.microsoft.com/en-in/documentation/articles/web-sites-create-web-jobs/#CreateScheduledCRON
Note: This technique is available to Web Apps running in Basic, Standard or Premium mode, and requires the Always On setting to be enabled on the app.
For this to work, simply create a file called Settings.job
For instance, to trigger the WebJob every 15 minutes, your settings.job would have:
"schedule": "0 */15 * * * *"
Now as part of the build this file must also be packaged to the Web Deploy package of the Web Job.
To do that, ensure this file is copied to the Build Output Directory.
There you go! You now have a custom scheduled WebJob using CRON Expression as well.
Content: Manigandan B
Review: Venkat NA