8

I have a Visual Studio 2017 solution with both an ASP.NET Web Application project (called UI) and an Azure WebJob project (called WebJobs). I have configured both to deploy to Azure from within Visual Studio (right click, publish) to the same App Service. The solution is also configured to build whenever I push to VSTS.

I would like to set up VSTS to also deploy both projects upon successful builds but I cam having problems.

My understanding is that to achieve this I need to create a release definition that is linked to my build definition with a "Deploy Azure App Service" task added to the pipeline. I tried this and got an error because more than one .zip file was found in the artifacts folder which advised me to make the filter more specific, so I changed the "Package or folder" option from $(System.DefaultWorkingDirectory)/**/*.zip to $(System.DefaultWorkingDirectory)/**/UI.zip. This got around the error but now obviously it's only deploying my App (UI).

My next step was to try creating a separate Environment for the WebJob project and specify $(System.DefaultWorkingDirectory)/**/WebJobs.zip as the Package. Now both environments "successfully" deploys but it breaks my App and I am pretty sure it has deployed the WebJob over the top of the App (I don't know how to confirm this belief...).

I notice that when you add an Environment to the release definition and choose a template, under "Azure App Service Deployment" it says: "Deploy your application to Azure App Services. Choose from Web App On Windows, Linux, Containers, Function Apps or Web Jobs" but when choose this template WebJob isn't listed in the "App Type" drop down!

I have found a few resources online regarding the deployment of of WebJobs from VSTS but they are all outdated and the options described no longer match those currently in VSTS.

SOLVED:

My problem was solved as a result of both David Ebbo's and starian chen's answers below.

Firstly you must right click your Web App project in Visual Studio and select Add > Existing Project as Azure WebJob and follow the wizard. Next you must ensure that the VSTS deploy task only finds one .zip package to deploy by updating the Package or folder path filter so it only finds the Web App's one; in my case it was $(System.DefaultWorkingDirectory)/**/UI.zip.

Big thanks to @DavidEbbo and @starianchen for their help!

Ben
  • 5,525
  • 8
  • 42
  • 66
  • does this help? https://stackoverflow.com/questions/45688605/deploy-azure-webjob-using-vsts – andresm53 Apr 26 '18 at 15:04
  • not so much as VSTS has changed since that answer and I think he is adding a task to the build definition rather than the release definition. – Ben Apr 26 '18 at 15:21

2 Answers2

10

All you have to do is create the WebJob project by right clicking on your Web App and choosing:

Add / New Azure WebJob project

Or if you already have a WebJobs project in the solution:

Add / Existing WebJob project

Once you do that, publishing the Web App automatically publishes the WebJob where it belongs. It all happens in a single zip file, and there is nothing special to do in VSTS. Do not try to publish the WebJob project individually once you do that.

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • 1
    Really? I feel like it should have been easier to find that out! Anyway, I have tried that but it is still producing 2 .zip files in the artifacts so I am still getting the "More than one package matched with specified pattern" error – Ben Apr 26 '18 at 15:57
  • 1
    Test this in stages. First, try to publish your app to a local folder. Does it have everything there including the WebJobs in App_Data? If that works, try to publish the same directly from VS to an App Service and make sure that works. If that all checks, we can look at VSTS. But really, they should all be exactly the same, as it's all msbuild in all cases. – David Ebbo Apr 26 '18 at 16:04
  • Firstly, thanks for your time David, I appreciate it! When I publish my App to Azure from VS into my App Service it does indeed update both the App and the WebJob, so we know that bits working. But when I push it to VSTS the build task is definitely creating 2 .zip files (unless they could be left over from a previous build?) – Ben Apr 26 '18 at 16:10
  • 1
    In VSTS, make sure that the only thing you tell it about is the Web App project. VSTS should know absolutely nothing about the WebJob, as it's really just a piece of the Web App. I'm not a VSTS expert, but I'm pretty sure that if you just tell it to deploy the Web App, it will do the right thing. – David Ebbo Apr 26 '18 at 16:19
  • Ah! Epiphany! So the build task is creating a .zip package for each executable project in my solution which happens to be the UI and WebJobs projects (I have some class libraries as well). I actually got it working this morning by telling the deploy task to only look for the UI.zip package. Again, thank you David – Ben Apr 27 '18 at 07:49
  • 1
    Great! It seems strange to me that they would generate a package for every executable in the solution. Some people have huge solutions with a bunch of projects that may have nothing to do with their web app, and building everything seems completely overkill. But anyway, glad there is a way to just deploy the one. – David Ebbo Apr 27 '18 at 16:40
  • The default path filter for projects to build is a wildcard I think. Easy enough to sort out once youve learnt this lesson though! – Ben Apr 29 '18 at 15:17
6

With webjob associated to web app, the webjob is included in the web app package, so you just need to deploy web app to azure app service.

It will generate webjob’s package too during publishing (that why there are two zip files), but you just need to specify web app package in Azure App Service deploy task. (Check Publish using Web Deploy option)

enter image description here

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • Thanks @starian. I came to the same conclusion just before I read your answer. – Ben Apr 27 '18 at 07:51
  • I actually would like to accept both your answer and @DavidEbbo's but sadly I cannot. For anyone reading this with the same problem, both answers are essential. I have accepted David's because his covered the part I was completely unable to solve myself. Thanks for you input starian – Ben Apr 27 '18 at 07:55
  • It's very important that the "Exclude files from the App_data folder" is unchecked. That setting will block webjob deployment because that is the folder webjobs deploy to – farlee2121 May 01 '19 at 20:08