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
4 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 bedotnet 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 atapp_data/jobs/continuous/[NameOfJob]
orapp_data/jobs/triggered/[NameOfJob]
. For the triggered job you could also add a schedule using asettings.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:
- Build/Publish your WebJob if necessary to get the executables
- 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. - Create the folder hierarchy
app_data/jobs/[triggered/continuous]/[nameOfJob]
and copy your executables into the lowest folder. Make surerun.cmd
is directly under the[nameOfJob]/
directory - Zip the app_data folder so that the zip-package contains the entire hierarchy
- Publish your zip file using the normal Azure App Service Deployment task (just like deploying the web app)
And that's it.

- 1,361
- 15
- 19
Yes you can.
Brady Gaster has written about this on a blog post (haven't tried it myself).
From what I gather, the TL;DR; summary is the following:
add a file named webjobs.props to the properties folder of the Web Application Project or Console Application you’re publishing
After that, edit the file so the ManagementCertificate
, SubscriptionId
and PublishSettingsPath
are filled with correct data.
Now you should be able to publish the files using the command
msbuild WebJobDemo.Web.csproj /p:DeployOnBuild=true /p:PublishProfile=WebJobDemo /p:VisualStudioVersion=12.0 /p:Password=asdfasdf
(Note, post is written for VS2013)
Afterwards you should see something like this.
You could of course automate this in VSTS (or any other build/deployment tool for that matter) whenever something is checked in to your repository.
A (rather complete) answer on how to do this in VSTS via the command-line can be found in this answer: https://stackoverflow.com/a/45703975/352640

- 4,244
- 1
- 40
- 64
You can do it through Continuous Integration Build (trigger the build once check in).
Regarding deploy WebJob, you can generate a package through Visual Studio Build task with /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.stagingDirectory)"
argument.
Then deploy it through Azure App Deployment task.
More information: Deploying and Schedule Azure WebJobs from VSTS to Azure Web App

- 33,174
- 2
- 29
- 53
In Visual Studio in order to enable automatic WebJobs deployment together with a Web project right-click the Web project in Solution Explorer, and then click: Add > Existing Project as Azure WebJob and create your WebJob.
More details can be found in an article by MS - webjobs-dotnet-deploy-vs

- 1,165
- 1
- 11
- 12
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/22174635) – Bsquare ℬℬ Feb 11 '19 at 13:10
-
I got it and tried to improve the answer. Thanks for feedback. – Honza P. Feb 11 '19 at 13:34