Deploy console webjob app to azure App service containing a webapi using azure devops pipelines - azure

I have 2 webAPI’s written in .net core 2.2.The 2 web api’s are triggered by web jobs which are console Apps in .netcore 2.2. They are all different projects and in different repositories in Azure DevOps.
I am trying to deploy the web Api's together with the webjob into 2 web app services(eg: WebApi1 + Web job1 into App service1 and WebApi2 + Web job2 into App service2) in Azure using the Azure DevOps build and release pipelines.
I am able to add the webjobs manually into App Service from Azure portal and it works fine.But I want to deploy it using Azure DevOps pipelines.
I tried different ways to publish the web jobs(console apps) with the web api in the app service, like trying to publish it to App_Data folder from Azure DevOps.
I mainly followed the blog below.
https://www.andrewhoefling.com/Blog/Post/deploying-dotnet-core-webjobs-to-azure-using-azure-pipelines
But when I try to publish the webjob it overwrites the web api code(all the 4 projects have seperate build/release pipelines). The webjob code gets deployed in the site/wwwroot folder rather than the site/job folder.
My Build steps:
My Release steps:
I am not sure what I am doing wrong.
Is there a way to copy the webjobs files into the same app service without overwritting the actual webapi code?

I asked this question a while on github repo azure-webjobs-sdk but the answer didn't help me as well...
i tried the following and it worked out for me:
In Azure Portal navigate to: App Service > Configuration > Path mappings > Virtual applications and directories
In DevOps configure your build pipeline like:
configure your release pipeline like:
configure the task:

I got it working by following below steps sequentially -
Deploy Webjob using App Service Deploy task which has below setting for deployment method -
Deploy API using App Service Deploy task which has below settings -
After these two steps, API and webjob work seamlessly in same app service.

Related

Azure WebApp WebJobs with Azure DevOps Build and Release Pipeline with via .zip

I have a files in azure repro and i need to zip after that i need to
updated into azure webapp to with new webjob with
manually/continuous.
2.I have created Build Pipeline and Release Pipeline. WebJobs are not created in the azure webapp
Kindly please help on this issues if any one knows.
The processes you have taken are just publishing the demo.zip file to the default production slot in your Web App. It is not creating a WebJobs in the Web App.
I am afraid that you have misunderstanding on WebJobs of Web App. It is a feature of Azure App Service that enables you to run a program or script in the same instance as a web app, API app, or mobile app. There is no additional cost to use WebJobs.
To create a WebJob in your Web App, normally, you need to manually add the WebJob in the web UI of your Web App.

exclude folder from delete in Azure Web APP deploy task

i've two applications (frontend and backend) in same Azure Web APP (Windows Plan).
The backend application is under wwwroot\back folder
The frontend application is under wwwroot folder
When i deploy the frontend using azure web app deploy task under Azure DevOps, the backend folder will be overwritting. Also , the same thing when deploy backend
Any idea , to do a exclude of same folder before deploy the front ?
Any idea , to do a exclude of same folder before deploy the front ?
In Azure Web APP deploy task, there is no such option could meet your requirements.
You could try to use Azure App Service deploy task.
In Azure App Service deploy task, you could enable the Select deployment method option and input the -skip argument
For example:
-skip:Directory=\\back
OR
-skip:skipAction=Delete,objectName=dirPath,absolutePath=wwwroot\\back
-skip:skipAction=Update,objectName=dirPath,absolutePath=wwwroot\\back
Then the target folder will skip the option to modify the content.
For more detailed information, you could refer to this ticket:Azure Pipelines: Exclude folders using Azure App Service Deploy and this blog: Demystifying MSDeploy skip rules.

Deploying several webjobs and a webapi to a single App Service on Azure with Devops

I am trying to deploy 4 or more webjobs and a webapi to a single app service on Azure, using Azure Devops.
I have read previously that to deploy a webjobs i needed to prp my artefact with the following tree organisation : webjobs/app_data/jobs/continuous ou webjobs/app_data/jobs/triggered
So i made it so that my build prepared the artefacts organised like this :
artefact
/WebApi
/...dlls and stuff
/webjob
/app_data
/jobs
/continuous
/webjob1
/...
/webjob2
/...
/triggered
/webjob3
/...
/Webjob4
/...
When i deploy webjobs, using the task Azure App Service Deploy, and pointing the folder webjob, i can see my webjobs being deployed all well.
But when i try to deploy the webApi as well, it doesn't work.
I first tried to deploy webjobs and webapi in two separated task (still using Azure App Service Deploy ) but one was overwritting the others.
I then tried using one task Azure App Service Deploy, by providing the top folder containing WebApi and webjob, but this doesn't seem to work.
I suppose there is a simple thing to do here, but i don't seem to be able to work it out ...
Is there any people who have managed to do this ?
Check this case: How do you deploy an Azure WebJob and App to the same App Service via VSTS?
You need to associate webjobs with web app, by right clicking your Web App project in Visual Studio and select Add > Existing Project as Azure WebJob and follow the wizard.
The webjobS are included in the web app package, then 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). Make sure the "Exclude files from the App_data folder" is unchecked:

Azure function app deploy and release pipeline error

I pushed my .net core function application using visual studio and now setting up release pipeline. I can publish and execute the application just fine and it works great on the Azure portal. However when I see the builds for releases in azure-devOps that slot fails with the following error.
2019-06-19T23:21:33.3543380Z ##[error]Error: Deployment of msBuild generated package is not supported. Change package format or use Azure App Service Deploy task. D:\a\r1\a\_...AVFunctionCore.zip
I am not sure where I need to check in my setup to even start diagnosing the issue.
Here are the pipeline steps.
I create a new stage and then select a template of type (Azure app service deployment)
Under tasks
App type is Function App on Windows
Give the app name, resource group , give the slot and
package folder as
$(System.DefaultWorkingDirectory)/**/AVFunctionCore.zip
Everything else on this is left as default.
Azure function app deploy and release pipeline error
According to the error message:
Deployment of msBuild generated package is not supported. Change
package format or use Azure App Service Deploy task.
It seems you are not using the correct task to publish the generated package. Since the generated package is .zip, you can try the suggestion as error message said use Azure App Service Deploy task.
Azure App Service Deploy task:
Use this task in a build or release pipeline to deploy to a range of
App Services on Azure. The task works on cross-platform agents running
Windows, Linux, or Mac and uses several different underlying
deployment technologies.
The task works for ASP.NET, ASP.NET Core, PHP, Java, Python, Go, and
Node.js based web applications.
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
Function Apps for Containers
WebJobs
Apps configured under Azure App Service Environments
Check this blog Visual Studio 2017 Tools for Azure Functions and Continuous Integration with VSTS for some more details.
Hope this helps.
I get predefined pipeline from VS integration. So for those you have the same case:
In GUI/Classic mode Release page -> edit pipeline
Edit task in stage section (this is responsible for deploying)
Replace Azure Web App task with Azure App Service deploy
I have more than one project (web api + azure function) in my solution. For the web app I used the zip file, but for the azure function to work I needed to publish the whole folder.
Azure Function
Package or folder:
$(System.DefaultWorkingDirectory)/_Backend/drop
Web Api
Package or folder:
$(System.DefaultWorkingDirectory)/_Backend/drop/ClientAPI.zip

Migrate database when deploying to Azure App Service

I'm using the ASP.NET Core & Angular startup template from ASP.NET Boilerplate with Multi-Tenancy disabled: 1 database with a single tenant(Default).
I'm also using TeamCity to build/test/publish the projects available in the startup template so I end up with 3 NuGet packages that are getting pushed to Octopus Deploy:
API (Host project, ASP.NET Core Web Application)
Migrator (Console application, capable of migrating the database(s))
UI (Angular App)
I want to deploy this setup to Azure with Octopus Deploy(self hosted, v2018.9.0) in the following way using 2 App Services(Host & UI) and 1 Azure SQL database(Host):
Take the UI and API applications offline, displaying a friendly maintenance message while updating the projects.
Migrate the database using the Migrator package
Deploy the API application package
Deploy the UI application package
Put the API application online, maybe some more tests to check that it's working correctly
Put the UI application online.
If all this was on-prem, I would have no questions. It's the Azure part that I can't figure out because I don't know how to do these things on Azure via Octopus Deploy:
Put an Azure App Service offline/online (using an app_offline.htm file)
Deploy the Migrator package to the API Azure App Service in a special folder(so that I don't overwrite the API deployment) and run the migrator: dotnet [migrator.dll] -q
I tried using the Octopus Deploy "Deploy an Azure Web App" but this step won't let me also deploy the migrator package and run it before the API package is deployed. Or does it? I don't know how.
I tried using the "Run an Azure PowerShell script" but this executes on the Octopus Deploy server and not on the Azure App Service environment right?
Maybe there are other, even better, approaches deploying this setup to Azure?
You can use App service slots to swap in/out version of your logical applications. When you swap there's a warming up that occurs and no loss of traffic.
So basically deploy to backup slot, then swap production with backup slot.
For the db I don't think your strategy is valid. There are some assumptions you are making that will not make your life easy. I would look at handling the db deployment separately with no breaking changes but that's my opinion.
I'm not familiar with Octopus or TeamCity so I won't go into details about those.

Resources