Azure App Service require custom startup command for simple Azure DevOps build/deploy. Why? - azure

DevOps Pipeline is using VSBuild#1 and PublishBuildArtifacts#1 to create zip artifact.
DevOps Releases is using Azure App Service deploy 4.* and Azure App Service Settings 1.* to deploy app on Azure Service App.
Both processes finish with green status but when I check service it says "Your app is running and wait for content".
Reason is that application is deployed to path: /wwwroot/Content/D_C/a/1/s/src/Project/obj/Release/net6.0/PubTmp/Out/ which is also visible in zip artifact: Content\D_C\a\1\s\src\Project\obj\Release\net6.0\PubTmp\Out.
When I setup start command to use this path it works, but:
I don't like fact I must to set it
If application is not web API but MVC app with own 'wwwroot' I have to move this manually or setup post-deployment script
I spent some time on debugging this issue and I can't believe that default settings don't work for basic scenario and deployment from VS/Rider is working ok!
On which step I have error? Path in ZIP is already wrong? Deployment is not smart enough? App Service is wrongly configured?

Related

Azure Function App Deploy from Azure Build Pipeline: 'credentials' cannot be null

I am trying to create a build pipeline in Azure DevOps to deploy an Azure Function Application automatically as part of a continous integration pipeline. When the Function App Deploy step is run, the step fails with 'credentials' cannot be null.
Does anyone know why this happens?
My Build Pipeline:
The Log output when the step runs:
The only thing that I think that it can be is the Azure Resource Manager subscription which I am using Publish Profile Based Authentication however I have managed to create a similar pipeline for a web application with a deploy option using this authentication and it worked successfully. I just cannot deploy the function application.
This same problem also ocurrs with publishing web apps I found. There are two different tasks that can be used for web apps to publish and you have to use the right one.
There is a task called Azure Web App Deploy that works.
Also a task called Azure App Service Deploy that doesn't.
This is with Publish Profile Based Authentication.
I found that to deploy the Function Application you can also use the Azure Web App Deploy task and it seems to work.
Just for a bit of context on this one.
The Azure Functions task will allow you to select - and even create - a Publish Profile based service connection. No warning is given, but - looking at the code - the task doesn't implement the needed fetching of the push profile.
At least the task - when selecting the service - should warn you that it doesn't handle Publish Profile authentication. At best they should implement it.
For the nerds in here, even more detail.
For tasks that work with Publish Profile authentication - like for example the Web App Deployment - you have something like this happening:
if (Service Endpoint is Publish Profile) {
publishProfileUtility.getSCMCredentialsFromPublishProfile();
}
Look at the link for the actual code.
On the other hand the Azure Functions will simply create the service with the passed endpoint and hope for the best.

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

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

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.

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.

Azure App Service API Deployment requires a restart

I use the Deploy Azure App Service VSTS task to deploy an asp dotnet core API to an Azure API app using the Publish using Web Deploy option. The task runs without any errors but somehow I have to restart the API to get the new version.
Is that intended? Is there any flag that I can set to immediately get the deployment "live"? As a workaround I can add a restart task but I hope there is another way....
Are you using App Service Local Cache? https://learn.microsoft.com/en-us/azure/app-service/app-service-local-cache
If you are you will need to remove WEBSITE_LOCAL_CACHE_OPTION = Always property of your web app to have your publish show right away.
Otherwise you can always use a deployment slot to test your app before swapping in production.

Resources