Troubles deploying my API to Azure App Service - azure

I'm developing a very simple API in ASP.NET Core for testing purposes.
I have an endpoint at https://localhost:5678/api/Values/addition/{a}/{b} which just adds number A and B and stores the result in a database.
The database is stored on Azure. In local, the application is running well and connects to my Azure SQL Server database successfully. I have hardcoded the connection string to avoid any complexifications which can result in errors. I'll change it later.
I have also created a Release Pipeline on Azure. First, here is the azure-pipelines.yml :
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
The release pipeline is triggered whenever a new push is detected on the master branch :
The job triggered is quite simple, it has a Run On Agent which triggers the deployment of my application to an Azure App Service like that :
steps:
- task: AzureRmWebAppDeployment#4
displayName: 'Deploy To Development'
inputs:
azureSubscription: '{MY SUBSCRIPTION ID}'
appType: webAppLinux
WebAppName: '{MY APP SERVICE NAME}'
deployToSlotOrASE: true
ResourceGroupName: '{MY RESOURCEGROUP NAME, SAME AS THE APP SERVICE}'
The build is successful, all jobs run successfully.
I can now navigate to my app service url https://{MY APP SERVICE NAME}.azurewebsites.net and get the welcome page of Azure :
I assume that at this point, I should be able to navigate to https://{MY APP SERVICE NAME}.azurewebsites.net/api/Values/addition/{a}/{b} and get a response from my API but instead of it, I get an error 404. The api endpoint just doesn't exist.
I've hardcoded everything to avoid system errors like non-acccessible external service, my log stream is also empty, and finally I've used kudu to verify that I have a correct web.config on my application. Everything is, I think, well published.
What am I missing here ?
EDIT 1 :
I've modified my Pipeline as following :
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: ubuntu-latest
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: '**/*Tests.csproj'
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '**/*sln'
feedsToUse: 'select'
vstsFeed: '{MY FEED}'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: false
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
modifyOutputPath: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
It modified my wwwroot/ of the App Service, but it still doesn't work.

I don't think you're actually pushing the zip to the app service (which would explain the 404). The AzureRmWebAppDeployment#4 task you're using requires a Package or packageForLinux parameter if you use the webAppLinux type (scroll down a bit from here), so that it knows what to publish to your app service.

Related

Two .NET core solutions (One containing APIs and another Azure Functions) build/release pipeline not working correctly

I have two solutions in my repository (one AppService (.NET Core API project) and another that is containing Azure Functions).
I am having 2 separate build pipelines and 2 separate release pipelines on Azure DevOps:
UserManagementAPI .yml file (API build pipeline):
trigger:
- dev
pool:
vmImage: 'windows-latest'
variables:
solution: '**/UserManagementAPI.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
displayName: 'Build'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Test'
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Publish'
inputs:
command: publish
publishWebProjects: true
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
publishLocation: pipeline
artifactName: userManagementAPI
UserManagementAPI.Functions .yml file (Functions build pipeline):
trigger:
- dev
pool:
vmImage: 'windows-latest'
variables:
solution: '**/UserManagementAPI.Functions.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
displayName: 'Build'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\UserManagement-Function.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Test'
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Publish'
inputs:
command: publish
publishWebProjects: true
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
publishLocation: pipeline
artifactName: userManagementAPI-functions
The build pipeline for UserManagementAPI is working just fine, artifact is created correctly, there is a zip file with everything included inside. The release pipeline is working fine as well, basically it's an Azure App Service Deploy task, here is the image:
On the other hand, build pipeline or release pipeline for azure functions are not working correctly, here is the artifact generated from UserManagementAPI.Functions build:
If I download the artifact, UserManagementAPI.zip file is containing all the dlls for UserManagementAPI solution (not the functions) and UserManagement-Function.zip is containing some weird data. Here is what is inside of it:
If I go deep into Content folder:
Here I can see my functions folders and bin folder, bin folder is containing all dlls of the functions (but it's too deep I think, it should be at the top of the zip, not inside Content\D_C\a\1\s\UserManagement.Functions\obj\Release\net6.0\PubTmp\Out\bin).
Each of the functions folders are containing one json file, here is one example:
The artifact files are generated in weird way and weird path in my opinion.
Here is the release pipeline of UserManagementAPI.Functions:
Both build pipelines (API and Functions) are executing successfully, they generate artifacts, release pipeline of UserManagementAPI is working fine but release pipeline of UserManagementAPI-Functions is throwing an error:
##[error]Error: Deployment of msBuild generated package is not supported. Change package format or use Azure App Service Deploy task. /home/azureuser/myagent/_work/r35/a/InternalUsers-Functions/userManagementAPI-functions/UserManagement-Function.zip
I have also found an article on stackoverflow having similar issue, but I couldn't solve it using Fernando Magno's suggestion and Leo Liu's suggestion is confusing to me, how can I have App Service for Azure Function.
To be honest, I'm new to release/build pipelines, especially having same repo with 2 solutions, so any help is appreciated here!

Azure devops pipeline only publishes web projects

The following YAML produced only web projects, my repo has 2 web api projects, 1 blazor and one regular asp.net core but only the asp.net core and blazor get published to 'drop' and the web api projects are ignored.
path of my .sln and files
\front-ends\webproject\webproject.csproj - regular razor project,
this gets added to the drop as webproject.zip
\front-ends\blazorproject\blazorproject.csproj - blazor project, this
gets added to the drop as blazorproject.zip
\services\api1\api.csproj - not showing in the drop
\services\api2\api2.csproj - not showing in the drop
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
steps:
- task: UseDotNet#2
displayName: ".NET Core 6"
inputs:
version: '6.0.x'
packageType: sdk
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
vstsFeed: 'f5775ae3-da0e-4b38-82f0-ce288b91309b'
- task: DotNetCoreCLI#2
displayName: "Publish"
inputs:
command: 'publish'
arguments: '-r win-x64 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
Add publishWebProjects: false to the `task: DotNetCoreCLI#2 (publish) as the default value is true

Cannot publish dotnet core web api app to Azure AppService

I need to build, test, and deploy a .net core web api app. I was hoping that this article titled Build, test, and deploy .NET Core apps would help me build, test, and deploy the app but for some reason I'm just not getting it.
I have a simple .net core 3.1 web api app.
I want to build and publish it to a virtual dir called 'api' on an Azure AppService.
I would prefer to publish using webdeploy but I will use whatever works if that is not possible.
The error I am getting on the AzureRmWebAppDeployment task is:
No package found with specified pattern: D:\a\1\s***.zipCheck if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.
What am I missing or doing wrong here?
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
feedsToUse: 'select'
vstsFeed: 'Project/Feed'
includeNuGetOrg: true
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\" /p:UseWPP_CopyWebApplication=true /p:OutDir="$(build.artifactstagingdirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'SubscriptionName'
appType: 'apiApp'
WebAppName: 'MyWebAppName'
VirtualApplication: 'api'
UseWebDeploy: true
You have output the build artifacts to folder $(Build.ArtifactStagingDirectory)(which is folder D:\a\1\a) In your VSBuild task and dotnet publish task. So you need to set the Package parameter to $(Build.ArtifactStagingDirectory)/**/*.zip for AzureRmWebAppDeployment task.
See below:
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'SubscriptionName'
appType: 'apiApp'
WebAppName: 'MyWebAppName'
VirtualApplication: 'api'
UseWebDeploy: true
Package: '$(Build.ArtifactStagingDirectory)/**/*.zip'
If you donot specify the Package parameter for AzureRmWebAppDeployment task. The default value is $(System.DefaultWorkingDirectory)/**/*.zip, which makes AzureRmWebAppDeployment task look for the deployment artifacts in folder $(System.DefaultWorkingDirectory) (which is folder D:\a\1\s in build agent) and its subfolders. Since you output the build artifacts to folder $(Build.ArtifactStagingDirectory), that's why you saw the error No package found with specified pattern: D:\a\1\s***.zip.
See document Azure App Service Deploy task for more information.

Unable to Publish the project from Azure DEVOPS

I am new for azure devops and learning purpose create new basic account from azure. I created new projects and did require changes. This project publishing the code into azure VM and it's giving error in final step.
Step: IIS Web App Deploy
Error: No package found with specified pattern.Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.
YAML for Release:
steps:
- task: IISWebAppManagementOnMachineGroup#0
displayName: 'IIS Web App Manage'
inputs:
IISDeploymentType: '$(Parameters.IISDeploymentType)'
ActionIISWebsite: '$(Parameters.ActionIISWebsite)'
WebsiteName: '$(Parameters.WebsiteName)'
WebsitePhysicalPath: '%SystemDrive%\inetpub\wwwroot\DD'
AddBinding: '$(Parameters.AddBinding)'
Bindings: '$(Parameters.Bindings)'
CreateOrUpdateAppPoolForWebsite: true
AppPoolNameForWebsite: DD
ParentWebsiteNameForVD: '$(Parameters.WebsiteName)'
VirtualPathForVD: '$(Parameters.VirtualPathForApplication)'
ParentWebsiteNameForApplication: '$(Parameters.WebsiteName)'
VirtualPathForApplication: '$(Parameters.VirtualPathForApplication)'
AppPoolName: '$(Parameters.AppPoolName)
steps:
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'IIS Web App Deploy'
inputs:
WebSiteName: '$(Parameters.WebsiteName)'
Package: '$(System.DefaultWorkingDirectory)/_ABC.API/drop/*.zip'
RemoveAdditionalFilesFlag: true
TakeAppOfflineFlag: true
XmlVariableSubstitution: True
Build YAML:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: CopyFiles#2
inputs:
SourceFolder: '$(agent.builddirectory)'
Contents: |
|
**\*.runsettings
**\*FunctionalTest*\**\bin\$(BuildConfiguration)\**
TargetFolder: '''$(build.artifactstagingdirectory)\FunctionalTests'''
- task: PublishBuildArtifacts#1
inputs:
artifactName: 'drop'
pathToPublish: '$(build.artifactStagingDirectory)'
Error Logs:
2020-04-19T10:02:47.0130907Z ##[section]Starting: IIS Web App Deploy
2020-04-19T10:02:47.0236460Z ==============================================================================
2020-04-19T10:02:47.0236816Z Task : IIS web app deploy
2020-04-19T10:02:47.0237124Z Description : Deploy a website or web application using Web Deploy
2020-04-19T10:02:47.0237414Z Version : 0.156.9
2020-04-19T10:02:47.0237649Z Author : Microsoft Corporation
2020-04-19T10:02:47.0238051Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/deploy/iis-web-app-deployment-on-machine-group
2020-04-19T10:02:47.0238500Z ==============================================================================
2020-04-19T10:02:47.8446908Z ##[error]Error: No package found with specified pattern.<br/>Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.
2020-04-19T10:02:47.8471615Z ##[section]Finishing: IIS Web App Deploy
Please help to find the issue
Trying to change the section Package to use the path from pathToPublish by default it was System.DefaultWorkingDirectory.
- task: PublishBuildArtifacts#1
inputs:
artifactName: 'drop'
pathToPublish: '$(build.artifactStagingDirectory)'
Change in IISWebAppDeploymentOnMachineGroup task:
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'IIS Web App Deploy'
inputs:
WebSiteName: '$(Parameters.WebsiteName)'
Package: '$(build.artifactStagingDirectory)/*.zip'
RemoveAdditionalFilesFlag: true
TakeAppOfflineFlag: true
XmlVariableSubstitution: True
Build.ArtifactStagingDirectory :
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: c:\agent_work\1\a
System.DefaultWorkingDirectory :
The local path on the agent where your source code files are downloaded. For example: c:\agent_work\1\s
For this ,please refer to predefined variables.

Azure DevOps Doesn't Publish Web App from ZIP Deploy, Runs It as Read-Only ZIP Package Instead

We have an Azure DevOps Pipeline that runs our application as ZIP package https://learn.microsoft.com/en-us/azure/app-service/deploy-run-package
as opposed to ZIP Deploy. So we are not able to SFTP into our Web App and change something. Why does the Pipeline runs our application as ZIP package and how can we change this?
This is the Pipeline:
trigger: none
pool:
vmImage: 'windows-latest'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: 'Solution1.sln'
- task: VSBuild#1
inputs:
solution: '$(agent.builddirectory)\s\Folder\Project.csproj'
msbuildArgs: '/p:OutputPath="$(build.binariesDirectory)\Folder\bin" /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:publishUrl="$(build.artifactStagingDirectory)\ProjectTempFolder"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: CopyFiles#2
inputs:
SourceFolder: '$(build.artifactStagingDirectory)\ProjectTempFolder'
Contents: |
**
TargetFolder: '$(build.ArtifactStagingDirectory)\ProjectArtifacts'
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(build.ArtifactStagingDirectory)\ProjectArtifacts'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(build.ArtifactStagingDirectory)\Project.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(build.ArtifactStagingDirectory)\Project.zip'
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Subscription1'
appType: 'webApp'
WebAppName: 'CoolWebApp777'
packageForLinux: '$(build.ArtifactStagingDirectory)\Project.zip'
Why does the Pipeline runs our application as ZIP package and how can we change this?
It seems you want to disable to run your Web App from a package, AFAIK, the default version in the release pipeline is now set to Version 4. This version has the "Select deployment method" checkbox disabled, which in turn, allows the "Run as Package" feature by default as well. To change this value, go into the "Deploy Azure App Service" task for each environment and expand Additional Deployment Options. You’ll probably want to change it most often to Web Deploy:
Besides, you can turn that off by deleting the WEBSITE_RUN_FROM_ZIP or WEBSITE_RUN_FROM_PACKAGE application setting in the portal.
Note this will clear your web app until the next time you publish.
Hope this helps.

Resources