Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy Azure WebJob as part of automatic VSTS deployment

Is there a way of having my Azure WebJob automatically deploy without needing to right click and select "Publish as Azure WebJob" every time? i.e. when I check-in my solution it is automatically deploy to the Azure Portal webjob section

like image 388
Jaja1415 Avatar asked Oct 17 '17 08:10

Jaja1415


People also ask

For which Web App can you configure a WebJob?

For which web app can you configure a WebJob? Publishing a . NET Core WebJob to App Service from Visual Studio uses the same tooling as publishing an ASP.NET Core app.

What the task can be used to deploy to a range of Azure app services?

The task can be used to deploy to a range of Azure App Services such as: Web Apps on both Windows and Linux. Web Apps for Containers. Function Apps on both Windows and Linux.


1 Answers

While I tried to accomplish this, I found out that there is no tooling support for dotnet core projects as of now. The proposed webjobs.props/ msbuild solutions are all dotnet framework specific.

However I also found out that a webjob can be anything that's executable on the local machine (could be node.js or just a batch command).


The key is to understand how WebJobs are recognized by the host:

  • A WebJob on a Windows host is (by what I gathered from experimenting with it) just a run.cmd file that contains instructions on how to start the webJob. For dotnet core that would be dotnet MyDll.dll %* (%* to pass arguments for output redirection etc. down from the host).
  • Now depending on wether the job is continuous or triggered the run.cmd file needs to be located either at app_data/jobs/continuous/[NameOfJob] or app_data/jobs/triggered/[NameOfJob]. For the triggered job you could also add a schedule using a settings.job file like described here.
  • If there is a run.cmd at the proper location it will be recognized as a WebJob

Now to deploy a webjob using VSTS regardless of the runtime framework follow these steps:

  1. Build/Publish your WebJob if necessary to get the executables
  2. Add a run.cmd file next to your webjob executables that contains the proper startup instructions. You could also add settings.job here if needed.
  3. Create the folder hierarchy app_data/jobs/[triggered/continuous]/[nameOfJob] and copy your executables into the lowest folder. Make sure run.cmd is directly under the [nameOfJob]/ directory
  4. Zip the app_data folder so that the zip-package contains the entire hierarchy
  5. Publish your zip file using the normal Azure App Service Deployment task (just like deploying the web app)

And that's it.

like image 186
Peter Avatar answered Oct 14 '22 22:10

Peter